Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

.idea/
lib/
node_modules/
5 changes: 2 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[submodule "genesis"]
path = genesis
url = https://github.com/bnb-chain/bsc-genesis-contract.git
branch = master
ignore = dirty
url = https://github.com/simplechain-org/bsc-genesis-contract.git
branch = develop/v1.0.1
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# BSC Node Docker Image
FROM ubuntu:20.04

# Install dependencies
RUN apt-get update && apt-get install -y \
wget \
jq \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Create user
RUN useradd -m -s /bin/bash sipc2

# Set working directory
WORKDIR /home/sipc2

# Copy sipc2 binary and configuration
COPY bin/geth /usr/local/bin/geth
RUN chmod +x /usr/local/bin/geth

# Copy scripts
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Create data directory
RUN mkdir -p /home/sipc2/data

# Set ownership
RUN chown -R sipc2:sipc2 /home/sipc2

# Switch to sipc2 user
USER sipc2

# Expose ports
EXPOSE 8545 8546 30303

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8545 || exit 1

# Set entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
112 changes: 84 additions & 28 deletions bsc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,38 @@ sleepAfterStart=10
# stop geth client
function exit_previous() {
ValIdx=$1
ps -ef | grep geth$ValIdx | grep config |awk '{print $2}' | xargs kill
ps -ef | grep geth$ValIdx | grep config |awk '{print $2}' | xargs -r kill
sleep ${sleepBeforeStart}
}

# Check if validator is a file or directory and handle accordingly
function handle_validator() {
local validator_path=$1
local index=$2
local target_dir=$3

if [ -f "${validator_path}" ]; then
# It's a file containing the operator address
echo "Validator ${index} is a file, copying operator address file"
cp ${validator_path} ${target_dir}/
elif [ -d "${validator_path}" ]; then
# It's a directory containing the keystore
echo "Validator ${index} is a directory, copying keystore directory"
cp -r ${validator_path} ${workspace}/.local/
else
echo "Error: Validator ${index} is neither a file nor a directory"
exit 1
fi
}

function create_validator() {
rm -rf ${workspace}/.local
mkdir -p ${workspace}/.local

for ((i = 0; i < size; i++)); do
cp -r ${workspace}/keys/validator${i} ${workspace}/.local/
# Handle validator based on whether it's a file or directory
handle_validator "${workspace}/keys/validator${i}" ${i} "${workspace}/.local/validator${i}"
cp -r ${workspace}/keys/consensus${i} ${workspace}/.local/
cp -r ${workspace}/keys/bls${i} ${workspace}/.local/
done
}
Expand All @@ -47,23 +69,24 @@ function reset_genesis() {
if [ ! -f "${workspace}/genesis/genesis-template.json" ]; then
cd ${workspace} && git submodule update --init --recursive genesis
cd ${workspace}/genesis && git reset --hard ${GENESIS_COMMIT}
fi
cd ${workspace}/genesis
cp genesis-template.json genesis-template.json.bk
cp scripts/init_holders.template scripts/init_holders.template.bk
git stash
cd ${workspace} && git submodule update --remote --recursive genesis && cd ${workspace}/genesis
git reset --hard ${GENESIS_COMMIT}
mv genesis-template.json.bk genesis-template.json
mv scripts/init_holders.template.bk scripts/init_holders.template

poetry install --no-root
npm install
rm -rf lib/forge-std
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
cd lib/forge-std/lib
rm -rf ds-test
git clone https://github.com/dapphub/ds-test
cd ${workspace}/genesis
cp genesis-template.json genesis-template.json.bk
cp scripts/init_holders.template scripts/init_holders.template.bk
git stash
cd ${workspace} && git submodule update --remote --recursive genesis && cd ${workspace}/genesis
git reset --hard ${GENESIS_COMMIT}
mv genesis-template.json.bk genesis-template.json
mv scripts/init_holders.template.bk scripts/init_holders.template

poetry install --no-root
npm install
rm -rf lib/forge-std
forge install --no-git foundry-rs/forge-std@v1.7.3
cd lib/forge-std/lib
rm -rf ds-test
git clone https://github.com/dapphub/ds-test
fi
}

function prepare_config() {
Expand All @@ -73,10 +96,25 @@ function prepare_config() {
echo "passedHardforkTime "${passedHardforkTime} > ${workspace}/.local/hardforkTime.txt
initHolders=${INIT_HOLDER}
for ((i = 0; i < size; i++)); do
for f in ${workspace}/.local/validator${i}/keystore/*; do
# Check if validator is a file or directory and extract operator address accordingly
if [ -f "${workspace}/keys/validator${i}" ]; then
# Read operator address from the file
operator_addr=$(cat ${workspace}/keys/validator${i})
elif [ -d "${workspace}/keys/validator${i}" ]; then
# Extract operator address from keystore
for f in ${workspace}/keys/validator${i}/keystore/*; do
operator_addr="0x$(cat ${f} | jq -r .address)"
done
else
echo "Error: Validator ${i} is neither a file nor a directory"
exit 1
fi

initHolders=${initHolders}","${operator_addr}
fee_addr=${operator_addr}

for f in ${workspace}/.local/consensus${i}/keystore/*; do
cons_addr="0x$(cat ${f} | jq -r .address)"
initHolders=${initHolders}","${cons_addr}
fee_addr=${cons_addr}
done

targetDir=${workspace}/.local/node${i}
Expand Down Expand Up @@ -128,7 +166,18 @@ function initNetwork() {
for ((i = 0; i < size; i++)); do
mkdir ${workspace}/.local/node${i}/geth
cp ${workspace}/keys/validator-nodekey${i} ${workspace}/.local/node${i}/geth/nodekey
mv ${workspace}/.local/validator${i}/keystore ${workspace}/.local/node${i}/ && rm -rf ${workspace}/.local/validator${i}

# Handle validator based on whether it's a file or directory
if [ -d "${workspace}/.local/validator${i}" ]; then
# Old format: validator is a directory with keystore
mv ${workspace}/.local/validator${i}/keystore ${workspace}/.local/node${i}/ && rm -rf ${workspace}/.local/validator${i}
else
# New format: validator is a file with operator address
# In this case, we don't need to move anything to node directory
rm -rf ${workspace}/.local/validator${i}
fi

mv ${workspace}/.local/consensus${i}/keystore ${workspace}/.local/node${i}/ && rm -rf ${workspace}/.local/consensus${i}
if [ ${EnableSentryNode} = true ]; then
mkdir ${workspace}/.local/sentry${i}/geth
cp ${workspace}/keys/sentry-nodekey${i} ${workspace}/.local/sentry${i}/geth/nodekey
Expand Down Expand Up @@ -225,7 +274,7 @@ function native_start() {
--metrics --metrics.addr localhost --metrics.port ${MetricsPort} --metrics.expensive \
--pprof --pprof.addr localhost --pprof.port ${PProfPort} \
--gcmode ${gcmode} --syncmode full --monitor.maliciousvote \
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
--override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
>> ${workspace}/.local/node${i}/bsc-node.log 2>&1 &
Expand All @@ -240,7 +289,7 @@ function native_start() {
--metrics --metrics.addr localhost --metrics.port $((MetricsPort+1)) --metrics.expensive \
--pprof --pprof.addr localhost --pprof.port $((PProfPort+1)) \
--gcmode ${gcmode} --syncmode full --monitor.maliciousvote \
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
--override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
>> ${workspace}/.local/sentry${i}/bsc-node.log 2>&1 &
Expand All @@ -257,7 +306,6 @@ function native_start() {
--metrics --metrics.addr localhost --metrics.port $((6160)) --metrics.expensive \
--pprof --pprof.addr localhost --pprof.port $((7160)) \
--gcmode ${gcmode} --syncmode full --monitor.maliciousvote \
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
>> ${workspace}/.local/fullnode0/bsc-node.log 2>&1 &
Expand All @@ -266,10 +314,13 @@ function native_start() {
}

function register_stakehub(){
if [ -f "${workspace}/keys/validator${i}" ];then
exit 1
fi
# wait feynman enable
sleep 45
for ((i = 0; i < size; i++));do
${workspace}/create-validator/create-validator --consensus-key-dir ${workspace}/keys/validator${i} --vote-key-dir ${workspace}/keys/bls${i} \
${workspace}/create-validator/create-validator --operator-key-dir ${workspace}/keys/validator${i} --consensus-key-dir ${workspace}/keys/consensus${i} --vote-key-dir ${workspace}/keys/bls${i} \
--password-path ${workspace}/keys/password.txt --amount 20001 --validator-desc Val${i} --rpc-url ${RPC_URL}
done
}
Expand Down Expand Up @@ -297,7 +348,12 @@ restart)
exit_previous $ValidatorIdx
native_start $ValidatorIdx
;;
regen-genesis)
create_validator
reset_genesis
prepare_config
;;
*)
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]"
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx] | regen-genesis"
;;
esac
esac
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Eth]
NetworkId = 714
NetworkId = 1914
SyncMode = "full"
NoPruning = false
NoPrefetch = false
Expand Down Expand Up @@ -40,6 +40,7 @@ GlobalQueue = 1024
Lifetime = 10800000000000

[Node]
DataDir = "/data"
IPCPath = "geth.ipc"
HTTPHost = "0.0.0.0"
InsecureUnlockAllowed = true
Expand Down
18 changes: 12 additions & 6 deletions create-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ var (
consensusKeyDir = flag.String("consensus-key-dir", "", "consensus keys dir")
voteKeyDir = flag.String("vote-key-dir", "", "vote keys dir")
passwordPath = flag.String("password-path", "", "password dir")
operatorKeyDir = flag.String("operator-key-dir", "", "operator keys dir")
)

func main() {
flag.Parse()

if *consensusKeyDir == "" {
panic("consensus-keys-dir is required")
}
Expand All @@ -43,6 +43,9 @@ func main() {
if *passwordPath == "" {
panic("password-path is required")
}
if *operatorKeyDir == "" {
*operatorKeyDir = *consensusKeyDir
}

client, err := ethclient.Dial(*rpcUrl)
if err != nil {
Expand All @@ -56,9 +59,12 @@ func main() {
password := string(bytes.TrimSpace(bz))

consensusKs := keystore.NewKeyStore(*consensusKeyDir+"/keystore", keystore.StandardScryptN, keystore.StandardScryptP)
operatorKs := keystore.NewKeyStore(*operatorKeyDir+"/keystore", keystore.StandardScryptN, keystore.StandardScryptP)
consensusAddr := consensusKs.Accounts()[0].Address
consensusAcc := accounts.Account{Address: consensusAddr}
err = consensusKs.Unlock(consensusAcc, password)

operatorAddr := operatorKs.Accounts()[0].Address
operatorAcc := accounts.Account{Address: operatorAddr}
err = operatorKs.Unlock(operatorAcc, password)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -94,7 +100,7 @@ func main() {
paddedChainIdBytes := make([]byte, 32)
copy(paddedChainIdBytes[32-len(chainId.Bytes()):], chainId.Bytes())

msgHash := crypto.Keccak256(append(consensusAddr.Bytes(), append(pubKey[:], paddedChainIdBytes...)...))
msgHash := crypto.Keccak256(append(operatorAddr.Bytes(), append(pubKey[:], paddedChainIdBytes...)...))
req := validatorpb.SignRequest{
PublicKey: pubKey[:],
SigningRoot: msgHash,
Expand All @@ -114,7 +120,7 @@ func main() {
panic(err)
}

nonce, err := client.PendingNonceAt(context.Background(), consensusAddr)
nonce, err := client.PendingNonceAt(context.Background(), operatorAddr)
if err != nil {
panic(err)
}
Expand All @@ -132,7 +138,7 @@ func main() {
Data: data,
})

signedTx, err := consensusKs.SignTx(consensusAcc, tx, chainId)
signedTx, err := operatorKs.SignTx(operatorAcc, tx, chainId)
if err != nil {
panic(err)
}
Expand Down
Loading