Skip to content

Commit

Permalink
BEP126
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Sep 8, 2023
1 parent c15074e commit 0c57b5e
Show file tree
Hide file tree
Showing 37 changed files with 1,975 additions and 647 deletions.
2 changes: 2 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
chain:
make -C chains build
make -C chains network
# Wait for one epoch to use BEP-120 validator
sleep 100

.PHONY:contracts
contracts:
Expand Down
10 changes: 6 additions & 4 deletions e2e/chains/bsc/Dockerfile.bootstrap
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM ethereum/solc:0.6.4-alpine

RUN apk add --d --no-cache ca-certificates npm nodejs bash alpine-sdk
RUN apk add --d --no-cache ca-certificates npm nodejs bash alpine-sdk expect jq

RUN git clone https://github.com/binance-chain/bsc-genesis-contract.git /root/genesis
RUN cd /root/genesis && git checkout 461d9a1f0d0bcc5fc2d4cd39c4b748185eaae34c
RUN cd /root/genesis && npm install
RUN git clone https://github.com/binance-chain/bsc-genesis-contract.git -b v1.1.9 /root/genesis \
&& cd /root/genesis && npm ci

COPY scripts/contracts/SystemReward.template /root/genesis/contracts/SystemReward.template
COPY scripts/contracts/BSCValidatorSet.template /root/genesis/contracts/BSCValidatorSet.template
COPY scripts/generate-validator.js /root/genesis/generate-validator.js
COPY scripts/genesis-template.template /root/genesis/genesis-template.template
COPY scripts/init_holders.template /root/genesis/init_holders.template

Expand Down
7 changes: 5 additions & 2 deletions e2e/chains/bsc/Dockerfile.bsc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM golang:1.16-alpine
FROM golang:1.19-alpine

ARG GIT_SOURCE
ARG GIT_CHECKOUT_BRANCH

RUN apk add --no-cache make gcc musl-dev linux-headers git
RUN apk add --no-cache make cmake gcc musl-dev linux-headers git bash build-base libc-dev

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN echo v15
RUN cd / && git clone --depth 1 -b ${GIT_CHECKOUT_BRANCH} ${GIT_SOURCE} \
&& cd ./bsc && make geth

Expand Down
4 changes: 2 additions & 2 deletions e2e/chains/bsc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ bootstrap:

.PHONY:network
network:
docker compose -f docker-compose.simple.yml up -d bsc-rpc bsc-validator1-1 bsc-validator1-2 bsc-validator1-3 bsc-validator1-4 bsc-validator1-5
docker compose -f docker-compose.simple.yml up -d bsc-rpc2 bsc-validator2-1 bsc-validator2-2 bsc-validator2-3 bsc-validator2-4 bsc-validator2-5
docker compose -f docker-compose.simple.yml up -d bsc-rpc bsc-validator1-1 bsc-validator1-2 bsc-validator1-3
docker compose -f docker-compose.simple.yml up -d bsc-rpc2 bsc-validator2-1 bsc-validator2-2 bsc-validator2-3

.PHONY:network-down
network-down:
Expand Down
2 changes: 2 additions & 0 deletions e2e/chains/bsc/config/config-validator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Percentile = 60
OracleThreshold = 100

[Node]
BLSPasswordFile="/root/.ethereum/blspassword.txt"
BLSWalletDir="/root/.ethereum/bls/wallet"
DataDir = ""
InsecureUnlockAllowed = false
NoUSB = true
Expand Down
2 changes: 1 addition & 1 deletion e2e/chains/bsc/docker-compose.bsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ services:
dockerfile: Dockerfile.bsc
args:
GIT_SOURCE: https://github.com/binance-chain/bsc.git
GIT_CHECKOUT_BRANCH: v1.1.17
GIT_CHECKOUT_BRANCH: v1.2.10
image: bsc-geth:docker-local
10 changes: 6 additions & 4 deletions e2e/chains/bsc/docker-compose.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
environment:
BLOCKS_PER_EPOCH: 20
INIT_HOLDER_BALANCE: "500000000000000000000"
NUMS_OF_VALIDATOR: 5
NUMS_OF_VALIDATOR: 3
volumes:
- bsc-rpc:/root/storage/bsc-rpc
- bsc-validator1-1:/root/storage/bsc-validator1
Expand All @@ -34,7 +34,8 @@ services:
- ./scripts:/root/scripts
- ./config:/root/config
- ./init-holders:/root/init-holders
# - ./validators/keystore:/root/validators/keystore
- ./validators/bls:/root/validators/bls
- ./validators/keystore:/root/validators/keystore
command: /root/scripts/bootstrap.sh

bootstrap-simple2:
Expand All @@ -45,7 +46,7 @@ services:
environment:
BLOCKS_PER_EPOCH: 20
INIT_HOLDER_BALANCE: "500000000000000000000"
NUMS_OF_VALIDATOR: 5
NUMS_OF_VALIDATOR: 3
volumes:
- bsc-rpc2:/root/storage/bsc-rpc
- bsc-validator2-1:/root/storage/bsc-validator1
Expand All @@ -56,7 +57,8 @@ services:
- ./scripts:/root/scripts
- ./config:/root/config
- ./init-holders:/root/init-holders
# - ./validators/keystore:/root/validators/keystore
- ./validators/bls:/root/validators/bls
- ./validators/keystore:/root/validators/keystore
command: /root/scripts/bootstrap.sh

bsc-rpc: # This is the bootstrap node
Expand Down
22 changes: 14 additions & 8 deletions e2e/chains/bsc/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -eu

workspace=$(
cd $(dirname $0)
Expand All @@ -18,13 +17,20 @@ function prepare() {

function init_validator() {
node_id=$1
geth --datadir ${workspace}/storage/${node_id} account new --password /dev/null >${workspace}/storage/${node_id}Info
validatorAddr=$(cat ${workspace}/storage/${node_id}Info | grep 'Public address of the key' | awk '{print $6}')
#mkdir -p ${workspace}/storage/${node_id}/keystore
#cp ${workspace}/validators/keystore/${node_id} ${workspace}/storage/${node_id}/keystore/${node_id}
#validatorAddr="0xa7876ea32e7a748c697d01345145485561305b24"
echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000" >>${workspace}/genesis/validators.conf

# set validator address
mkdir -p ${workspace}/storage/${node_id}/keystore
cp ${workspace}/validators/keystore/${node_id} ${workspace}/storage/${node_id}/keystore/${node_id}
validatorAddr=0x$(cat ${workspace}/storage/${node_id}/keystore/${node_id} | jq .address | sed 's/"//g')
echo ${validatorAddr} >${workspace}/storage/${node_id}/address

# import BLS vote address
echo password01 > ${workspace}/storage/${node_id}/blspassword.txt
geth --datadir ${workspace}/storage/${node_id} bls account import ${workspace}/validators/bls/${node_id} --blspassword ${workspace}/storage/${node_id}/blspassword.txt --blsaccountpassword ${workspace}/storage/${node_id}/blspassword.txt
geth --datadir ${workspace}/storage/${node_id} bls account list --blspassword ${workspace}/storage/${node_id}/blspassword.txt
voteAddr=0x$(cat ${workspace}/validators/bls/${node_id} | jq .pubkey | sed 's/"//g')

echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000,${voteAddr}" >>${workspace}/genesis/validators.conf
}

function generate_genesis() {
Expand All @@ -36,7 +42,6 @@ function generate_genesis() {
node generate-validator.js
chainIDHex=$(printf '%04x\n' ${BSC_CHAIN_ID})
node generate-genesis.js --chainid ${BSC_CHAIN_ID} --bscChainId ${chainIDHex}
#cat ${workspace}/genesis/genesis.json
}

function init_genesis_data() {
Expand All @@ -57,6 +62,7 @@ prepare
# First, generate config for each validator
for ((i = 1; i <= ${NUMS_OF_VALIDATOR}; i++)); do
init_validator "bsc-validator${i}"
generate_validator_conf "bsc-validator${i}"
done

# Then, use validator configs to generate genesis file
Expand Down
2 changes: 1 addition & 1 deletion e2e/chains/bsc/scripts/bsc-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUS
--mine -unlock ${VALIDATOR_ADDR} --password /dev/null \
--light.serve 50 --pprof.addr 0.0.0.0 --metrics \
--rpc.allow-unprotected-txs --txlookuplimit 15768000 \
--pprof --ipcpath /gethipc
--pprof --ipcpath /gethipc --vote
Loading

0 comments on commit 0c57b5e

Please sign in to comment.