2021-10-18 18:16:32 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
workspace=$(cd `dirname $0`; pwd)/..
|
|
|
|
|
|
|
|
function prepare() {
|
|
|
|
if ! [[ -f /usr/local/bin/geth ]];then
|
|
|
|
echo "geth do not exist!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd ${workspace}/genesis
|
2023-12-06 18:32:31 +08:00
|
|
|
cp ${workspace}/storage/genesis.json ${workspace}/genesis/genesis.json
|
2021-10-18 18:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function init_validator() {
|
|
|
|
node_id=$1
|
2023-12-06 18:32:31 +08:00
|
|
|
rm -rf ${workspace}/storage/${node_id}
|
2021-10-18 18:16:32 +08:00
|
|
|
mkdir -p ${workspace}/storage/${node_id}
|
2023-12-06 18:32:31 +08:00
|
|
|
cp -r ${workspace}/storage/keystore ${workspace}/storage/${node_id}/
|
|
|
|
cp ${workspace}/storage/address ${workspace}/storage/${node_id}/address
|
2021-10-18 18:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function generate_genesis() {
|
2023-12-06 18:32:31 +08:00
|
|
|
cd ${workspace}/genesis/scripts/
|
2023-09-18 14:52:04 +08:00
|
|
|
node generate-validator.js
|
2021-10-18 18:16:32 +08:00
|
|
|
INIT_HOLDER_ADDRESSES=$(ls ${workspace}/init-holders | tr '\n' ',')
|
|
|
|
INIT_HOLDER_ADDRESSES=${INIT_HOLDER_ADDRESSES/%,/}
|
2023-09-18 14:52:04 +08:00
|
|
|
node generate-initHolders.js --initHolders ${INIT_HOLDER_ADDRESSES}
|
2023-12-06 18:32:31 +08:00
|
|
|
|
|
|
|
cd ${workspace}/genesis
|
|
|
|
#source /root/.profile && foundryup
|
|
|
|
#forge install --no-git --no-commit foundry-rs/forge-std@v1.1.1
|
|
|
|
bash ${workspace}/genesis/scripts/generate.sh local
|
2021-10-18 18:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function init_genesis_data() {
|
|
|
|
node_type=$1
|
|
|
|
node_id=$2
|
2024-03-25 16:49:55 +08:00
|
|
|
geth --datadir ${workspace}/storage/${node_id} init ${workspace}/genesis/genesis.json
|
2021-10-18 18:16:32 +08:00
|
|
|
cp ${workspace}/config/config-${node_type}.toml ${workspace}/storage/${node_id}/config.toml
|
|
|
|
sed -i -e "s/{{NetworkId}}/${BSC_CHAIN_ID}/g" ${workspace}/storage/${node_id}/config.toml
|
|
|
|
if [ "${node_id}" == "bsc-rpc" ]; then
|
|
|
|
cp ${workspace}/init-holders/* ${workspace}/storage/${node_id}/keystore
|
|
|
|
cp ${workspace}/genesis/genesis.json ${workspace}/storage/${node_id}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-04-10 18:36:45 +08:00
|
|
|
function prepareBLSWallet(){
|
|
|
|
node_id=$1
|
2023-12-06 18:32:31 +08:00
|
|
|
echo "1234567890" > ${workspace}/storage/${node_id}/blspassword.txt
|
|
|
|
geth bls account new --datadir ${workspace}/storage/${node_id} --blspassword ${workspace}/storage/${node_id}/blspassword.txt
|
2023-04-10 18:36:45 +08:00
|
|
|
|
|
|
|
sed -i -e 's/DataDir/BLSPasswordFile = \"{{BLSPasswordFile}}\"\nBLSWalletDir = \"{{BLSWalletDir}}\"\nDataDir/g' ${workspace}/storage/${node_id}/config.toml
|
|
|
|
PassWordPath="/root/.ethereum/blspassword.txt"
|
|
|
|
sed -i -e "s:{{BLSPasswordFile}}:${PassWordPath}:g" ${workspace}/storage/${node_id}/config.toml
|
|
|
|
WalletPath="/root/.ethereum/bls/wallet"
|
|
|
|
sed -i -e "s:{{BLSWalletDir}}:${WalletPath}:g" ${workspace}/storage/${node_id}/config.toml
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:16:32 +08:00
|
|
|
prepare
|
2023-12-06 18:32:31 +08:00
|
|
|
NUMS_OF_VALIDATOR=1
|
2023-04-10 18:36:45 +08:00
|
|
|
# Step 1, generate config for each validator
|
2021-10-18 18:16:32 +08:00
|
|
|
for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do
|
|
|
|
init_validator "bsc-validator${i}"
|
|
|
|
done
|
|
|
|
|
2023-04-10 18:36:45 +08:00
|
|
|
# Step 2, use validator configs to generate genesis file
|
2023-12-06 18:32:31 +08:00
|
|
|
#generate_genesis
|
2021-10-18 18:16:32 +08:00
|
|
|
|
2023-04-10 18:36:45 +08:00
|
|
|
# Step 3, use genesis file to init cluster data
|
2021-10-18 18:16:32 +08:00
|
|
|
init_genesis_data bsc-rpc bsc-rpc
|
|
|
|
|
|
|
|
for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do
|
|
|
|
init_genesis_data validator "bsc-validator${i}"
|
|
|
|
done
|
2023-04-10 18:36:45 +08:00
|
|
|
|
|
|
|
#Step 4, prepare bls wallet, used by fast finality vote
|
|
|
|
prepareBLSWallet bsc-rpc
|
|
|
|
|
|
|
|
for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do
|
|
|
|
prepareBLSWallet "bsc-validator${i}"
|
|
|
|
done
|