mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
update validator initial configs
This commit is contained in:
parent
069cd8ebce
commit
a1e5a98377
5 changed files with 114 additions and 56 deletions
|
|
@ -1,6 +1,4 @@
|
|||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
|
||||
if [ ! -d /work/xdcchain/XDC/chaindata ]
|
||||
then
|
||||
if test -z "$PRIVATE_KEY"
|
||||
|
|
@ -26,41 +24,95 @@ do
|
|||
bootnodes="${bootnodes},$line"
|
||||
fi
|
||||
done < "$input"
|
||||
#check last line since it's not included in "read" command https://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line
|
||||
if [ -z "${bootnodes}" ]
|
||||
then
|
||||
bootnodes=$line
|
||||
else
|
||||
bootnodes="${bootnodes},$line"
|
||||
fi
|
||||
|
||||
log_level="${LOG_LEVEL:-3}"
|
||||
log_level=3
|
||||
if test -z "$LOG_LEVEL"
|
||||
then
|
||||
echo "Log level not set, default to verbosity of $log_level"
|
||||
else
|
||||
echo "Log level found, set to $LOG_LEVEL"
|
||||
log_level=$LOG_LEVEL
|
||||
fi
|
||||
|
||||
port="${PORT:-30303}"
|
||||
port=30303
|
||||
if test -z "$PORT"
|
||||
then
|
||||
echo "PORT not set, default to $port"
|
||||
else
|
||||
echo "PORT found, set to $PORT"
|
||||
port=$PORT
|
||||
fi
|
||||
|
||||
rpc_port="${RPC_PORT:-8545}"
|
||||
rpc_port=8545
|
||||
if test -z "$RPC_PORT"
|
||||
then
|
||||
echo "RPC_PORT not set, default to $rpc_port"
|
||||
else
|
||||
echo "RPC_PORT found, set to $RPC_PORT"
|
||||
rpc_port=$RPC_PORT
|
||||
fi
|
||||
|
||||
ws_port="${WS_PORT:-8555}"
|
||||
ws_port=8555
|
||||
if test -z "$WS_PORT"
|
||||
then
|
||||
echo "WS_PORT not set, default to $ws_port"
|
||||
else
|
||||
echo "WS_PORT found, set to $WS_PORT"
|
||||
ws_port=$WS_PORT
|
||||
fi
|
||||
|
||||
netstats="${NODE_NAME}-${wallet}:xinfin_xdpos_hybrid_network_stats@devnetstats.apothem.network:2000"
|
||||
instance_ip=$(ifconfig eth0 | awk '/inet addr:/ {print $2}' | cut -d: -f2)
|
||||
if test -z "$INSTANCE_IP"
|
||||
then
|
||||
echo "INSTANCE_IP not set, default to $instance_ip"
|
||||
else
|
||||
echo "INSTANCE_IP found, set to $INSTANCE_IP"
|
||||
instance_ip=$INSTANCE_IP
|
||||
fi
|
||||
|
||||
sync_mode=full
|
||||
if test -z "$SYNC_MODE"
|
||||
then
|
||||
echo "SYNC_MODE not set, default to full" #full or fast
|
||||
else
|
||||
echo "SYNC_MODE found, set to $SYNC_MODE"
|
||||
sync_mode=$SYNC_MODE
|
||||
fi
|
||||
|
||||
gc_mode=archive
|
||||
if test -z "$GC_MODE"
|
||||
then
|
||||
echo "GC_MODE not set, default to archive" #full or archive
|
||||
else
|
||||
echo "GC_MODE found, set to $GC_MODE"
|
||||
gc_mode=$GC_MODE
|
||||
fi
|
||||
|
||||
|
||||
echo "Running a node with wallet: ${wallet}"
|
||||
echo "Running a node with wallet: ${wallet} at IP: ${instance_ip}"
|
||||
echo "Starting nodes with $bootnodes ..."
|
||||
|
||||
# Note: --gcmode=archive means node will store all historical data. This will lead to high memory usage. But sync mode require archive to sync
|
||||
# https://github.com/XinFinOrg/XDPoSChain/issues/268
|
||||
|
||||
XDC --ethstats ${netstats} \
|
||||
--gcmode archive \
|
||||
XDC \
|
||||
--gcmode ${gc_mode} --syncmode ${sync_mode} \
|
||||
--nat extip:${instance_ip} \
|
||||
--bootnodes ${bootnodes} \
|
||||
--syncmode full \
|
||||
--datadir /work/xdcchain \
|
||||
--port $port \
|
||||
--rpc --rpccorsdomain "*" \
|
||||
--rpcaddr 0.0.0.0 \
|
||||
--rpcport $rpc_port \
|
||||
--rpcapi db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
|
||||
--rpcvhosts "*" \
|
||||
--unlock "${wallet}" \
|
||||
--password /work/.pwd --mine \
|
||||
--gasprice "1" --targetgaslimit "420000000" \
|
||||
--verbosity ${log_level} \
|
||||
--port $port --http --http-corsdomain "*" --http-addr 0.0.0.0 \
|
||||
--http-port $rpc_port \
|
||||
--http-api db,eth,net,txpool,web3,XDPoS \
|
||||
--http-vhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
|
||||
--miner-gasprice "1" --miner-gaslimit "50000000" --verbosity ${log_level} \
|
||||
--debugdatadir /work/xdcchain \
|
||||
--ws \
|
||||
--wsaddr=0.0.0.0 \
|
||||
--wsport $ws_port \
|
||||
--wsorigins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log
|
||||
--store-reward \
|
||||
--ws --ws-addr=0.0.0.0 --ws-port $ws_port \
|
||||
--ws-origins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log
|
||||
|
|
|
|||
|
|
@ -290,20 +290,11 @@ func (w *wizard) makeGenesis() {
|
|||
|
||||
fmt.Println()
|
||||
fmt.Println("What is minimum staking threshold to become a Validator? (default = 10M)")
|
||||
threshold := new(big.Int)
|
||||
var threshold uint64
|
||||
if input != nil {
|
||||
threshold.SetString("10000000000000000000", 10) // 10M
|
||||
threshold = input.StakingThreshold
|
||||
} else {
|
||||
threshold.SetString("10000000000000000000", 10) // 10M
|
||||
}
|
||||
|
||||
validatorCap := new(big.Int)
|
||||
validatorCap.SetString("50000000000000000000000", 10)
|
||||
var validatorCaps []*big.Int
|
||||
genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+crypto.SignatureLength)
|
||||
for i, signer := range signers {
|
||||
validatorCaps = append(validatorCaps, validatorCap)
|
||||
copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:])
|
||||
threshold = uint64(w.readDefaultInt(10000000))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
|
@ -317,11 +308,12 @@ func (w *wizard) makeGenesis() {
|
|||
}
|
||||
blocksPerYear := uint64(31536000 / genesis.Config.XDPoS.Period)
|
||||
epochsPerYear := blocksPerYear / genesis.Config.XDPoS.Epoch
|
||||
rewardsPerYear := float64(threshold.Uint64()) * (float64(yield) / float64(100))
|
||||
rewardPerEpoch := uint64(rewardsPerYear / float64(epochsPerYear))
|
||||
rewardsPerYear := float64(threshold) * (float64(yield) / float64(100))
|
||||
rewardPerEpochPerMN := uint64(rewardsPerYear / float64(epochsPerYear))
|
||||
totalRewardPerEpoch := rewardPerEpochPerMN * uint64(len(signers))
|
||||
fmt.Println()
|
||||
fmt.Println("Calculated Masternode reward per epoch based on yield: ", rewardPerEpoch)
|
||||
genesis.Config.XDPoS.Reward = rewardPerEpoch
|
||||
fmt.Println("Calculated Total Masternode rewards per epoch based on yield: ", totalRewardPerEpoch)
|
||||
genesis.Config.XDPoS.Reward = totalRewardPerEpoch
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("What is foundation wallet address (collect 10% of all rewards)? (default = xdc0000000000000000000000000000000000000068)")
|
||||
|
|
@ -337,7 +329,16 @@ func (w *wizard) makeGenesis() {
|
|||
contractBackend := backends.NewXDCSimulatedBackend(types.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||
transactOpts := bind.NewKeyedTransactor(pKey)
|
||||
|
||||
validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, owner)
|
||||
minDeposit := new(big.Int).SetUint64(threshold)
|
||||
minDeposit.Mul(minDeposit, big.NewInt(1e18)) //convert to wei
|
||||
validatorCap := new(big.Int).Set(minDeposit)
|
||||
var validatorCaps []*big.Int
|
||||
genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+crypto.SignatureLength)
|
||||
for i, signer := range signers {
|
||||
validatorCaps = append(validatorCaps, validatorCap)
|
||||
copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:])
|
||||
}
|
||||
validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, owner, minDeposit, nil)
|
||||
if err != nil {
|
||||
fmt.Println("Can't deploy root registry")
|
||||
}
|
||||
|
|
@ -505,8 +506,8 @@ func (w *wizard) makeGenesis() {
|
|||
}
|
||||
for _, address := range addresses {
|
||||
baseBalance := big.NewInt(0) // 21m
|
||||
baseBalance.Add(baseBalance, big.NewInt(21*1000*1000))
|
||||
baseBalance.Mul(baseBalance, big.NewInt(1000000000000000000))
|
||||
baseBalance.Add(baseBalance, big.NewInt(21_000_000))
|
||||
baseBalance.Mul(baseBalance, big.NewInt(1e18))
|
||||
genesis.Alloc[address] = types.Account{
|
||||
Balance: baseBalance,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ var (
|
|||
XDCNativeAddressBinary = HexToAddress("0x0000000000000000000000000000000000000001")
|
||||
LendingLockAddressBinary = HexToAddress("0x0000000000000000000000000000000000000011")
|
||||
MintedRecordAddressBinary = HexToAddress("0x000000000000000000000000000000000000009a")
|
||||
SwapAddressBinary = HexToAddress("0x000000000000000000000000000000000000008e") //confirm Address
|
||||
)
|
||||
|
||||
// Hash represents the 32 byte Keccak256 hash of arbitrary data.
|
||||
|
|
|
|||
|
|
@ -43,17 +43,23 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
|||
}, nil
|
||||
}
|
||||
|
||||
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address) (common.Address, *Validator, error) {
|
||||
minDeposit := new(big.Int)
|
||||
minDeposit.SetString("10000000000000000000000000", 10)
|
||||
minVoterCap := new(big.Int)
|
||||
minVoterCap.SetString("25000000000000000000000", 10)
|
||||
// Deposit 50K XDC
|
||||
// Min Voter Cap 10 XDC
|
||||
// 150 masternodes
|
||||
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address, minDeposit *big.Int, minVoterCap *big.Int) (common.Address, *Validator, error) {
|
||||
if minDeposit == nil {
|
||||
minDeposit = new(big.Int)
|
||||
minDeposit.SetString("10000000", 10) // 10M
|
||||
minDeposit.Mul(minDeposit, big.NewInt(1e18)) //convert to wei
|
||||
}
|
||||
if minVoterCap == nil {
|
||||
minVoterCap = new(big.Int).Set(minDeposit)
|
||||
minVoterCap.Div(minVoterCap, big.NewInt(400)) //set votercap to 0.25% of candidate deposit (25K XDC)
|
||||
}
|
||||
|
||||
// Deposit 10M XDC
|
||||
// Min Voter Cap 25K XDC
|
||||
// 108 masternodes
|
||||
// Candidate Delay Withdraw 30 days = 1296000 blocks
|
||||
// Voter Delay Withdraw 10 days = 432000 blocks
|
||||
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(18), big.NewInt(1296000), big.NewInt(432000))
|
||||
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(108), big.NewInt(1296000), big.NewInt(432000))
|
||||
if err != nil {
|
||||
return validatorAddr, nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func TestValidator(t *testing.T) {
|
|||
|
||||
validatorCap := new(big.Int)
|
||||
validatorCap.SetString("50000000000000000000000", 10)
|
||||
validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{validatorCap}, addr)
|
||||
validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{validatorCap}, addr, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("can't deploy root registry: %v", err)
|
||||
}
|
||||
|
|
@ -280,7 +280,7 @@ func TestStatedbUtils(t *testing.T) {
|
|||
contractBackend := backends.NewXDCSimulatedBackend(genesisAlloc, 10000000, params.TestXDPoSMockChainConfig)
|
||||
transactOpts := bind.NewKeyedTransactor(key)
|
||||
|
||||
validatorAddress, _, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr, acc3Addr}, []*big.Int{validatorCap, validatorCap}, addr)
|
||||
validatorAddress, _, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr, acc3Addr}, []*big.Int{validatorCap, validatorCap}, addr, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("can't deploy root registry: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue