github.com/aergoio/aergo@v1.3.1/consensus/impl/raftv2/test/add_member.sh (about)

     1  #!/usr/bin/env bash
     2  source test_common.sh
     3  
     4  addnode=$1
     5  
     6  echo "add member $addnode"
     7  
     8  if [ "$1" = "" ] || [[ "$1" != aergo* ]] ;then
     9  	echo "use:add_member.sh aergo4|aergo5|aergo6|aergo7 usebackup"
    10  	exit 100
    11  fi
    12  
    13  usebackup=0
    14  if [ "$2" == "usebackup" ]; then
    15  	usebackup=1	
    16  
    17  	echo "try to join $addnode with backup"
    18  fi
    19  
    20  reqport=$3
    21  if [ "$reqport" = "" ];then
    22  	reqport=10001
    23  fi
    24  
    25  leader=$(aergocli -p $reqport blockchain | jq .ConsensusInfo.Status.Leader)
    26  leader=${leader//\"/}
    27  if [[ $leader != aergo* ]]; then
    28  	echo "leader not exist"
    29  	exit 100
    30  fi
    31  
    32  leaderport=${ports[$leader]}
    33  prevCnt=$(getClusterTotal $leaderport)
    34  
    35  echo "leader=$leader, port=$leaderport, prevTotal=$prevCnt"
    36  
    37  # By RPC
    38  #echo "aergocli -p $leaderport cluster add --name \"$addnode\" --address \"/ip4/127.0.0.1/${httpports[$addnode]}\" --peerid \"${peerids[$addnode]}\""
    39  #aergocli -p $leaderport cluster add --name "$addnode" --address "/ip4/127.0.0.1/${httpports[$addnode]}" --peerid "${peerids[$addnode]}"
    40  
    41  # By Enterprise Tx
    42  walletFile="$TEST_RAFT_INSTANCE/genesis_wallet.txt"
    43  ADMIN=
    44  getAdminUnlocked $leaderport $walletFile ADMIN
    45  
    46  addJson="$(makeAddMemberJson $addnode)"
    47  
    48  echo "aergocli -p "$leaderport" contract call --governance "$ADMIN" aergo.enterprise changeCluster "$addJson
    49  aergocli -p $leaderport contract call --governance $ADMIN aergo.enterprise changeCluster "$addJson"
    50  echo "add Done" 
    51  
    52  mySvrport=${svrports[$addnode]}
    53  mySvrName=${svrname[$addnode]}
    54  myConfig="$mySvrName.toml"
    55  
    56  
    57  for i in {1..5}; do
    58  	echo ${svrname["aergo$i"]}
    59  done
    60  echo "new svr=$mySvrport $mySvrName, $myConfig"
    61  
    62  reqCnt=$((prevCnt+1))
    63  echo "waitClusterTotal=$reqCnt"
    64  waitClusterTotal $reqCnt 600 $reqport
    65  if [ $? -ne 1 ]; then
    66  	echo "add failed"
    67  	exit 100
    68  fi
    69  
    70  echo "Get config of added member"
    71  echo "cp $TEST_RAFT_INSTANCE_CONF/$myConfig $TEST_RAFT_INSTANCE"
    72  cp $TEST_RAFT_INSTANCE_CONF/$myConfig $TEST_RAFT_INSTANCE
    73  
    74  pushd $TEST_RAFT_INSTANCE
    75  if [ "$usebackup" == "0" ]; then
    76  	echo "init genesis for $mySvrName"
    77  	init_genesis.sh $mySvrName > /dev/null 2>&1
    78  else 
    79  	echo "join using backup: $mySvrName"
    80  	do_sed.sh $myConfig "usebackup=false" "usebackup=true" "/"
    81  	run_svr.sh $mySvrName
    82  fi
    83  popd