github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/dev/testnet/testnet.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  NUM_NODE=4
     4  
     5  # tackle size chronic goose deny inquiry gesture fog front sea twin raise
     6  # acid pulse trial pill stumble toilet annual upgrade gold zone void civil
     7  # antique onion adult slot sad dizzy sure among cement demise submit scare
     8  # lazy cause kite fence gravity regret visa fuel tone clerk motor rent
     9  HARDCODED_MNEMONIC=true
    10  
    11  set -e
    12  set -o errexit
    13  set -a
    14  set -m
    15  
    16  set -x # activate debugging
    17  
    18  source fbc.profile
    19  WRAPPEDTX=false
    20  PRERUN=false
    21  NUM_RPC=0
    22  WHITE_LIST=0x9119cE8bEA989Ee6D19514f4a8390F3503689D79,\
    23  0x3934c56b25c36a7f28DE3522b8Fd0c55B7D54722,\
    24  0x7E4A75569041996E869a0749Ed342fB13bD7d249,\
    25  0x631f017259c07E2A57fbda3f269DbdCF00c7979e,\
    26  testnet-node-ids
    27  
    28  
    29  while getopts "r:isn:b:p:c:Sxwk:" opt; do
    30    case $opt in
    31    i)
    32      echo "FBCHAIN_INIT"
    33      FBCHAIN_INIT=1
    34      ;;
    35    r)
    36      echo "NUM_RPC=$OPTARG"
    37      NUM_RPC=$OPTARG
    38      ;;
    39    w)
    40      echo "WRAPPEDTX=$OPTARG"
    41      WRAPPEDTX=true
    42      ;;
    43    x)
    44      echo "PRERUN=$OPTARG"
    45      PRERUN=true
    46      ;;
    47    s)
    48      echo "FBCHAIN_START"
    49      FBCHAIN_START=1
    50      ;;
    51    k)
    52      echo "LOG_SERVER"
    53      LOG_SERVER="--log-server $OPTARG"
    54      ;;
    55    c)
    56      echo "Test_CASE"
    57      Test_CASE="--consensus-testcase $OPTARG"
    58      ;;
    59    n)
    60      echo "NUM_NODE=$OPTARG"
    61      NUM_NODE=$OPTARG
    62      ;;
    63    b)
    64      echo "BIN_NAME=$OPTARG"
    65      BIN_NAME=$OPTARG
    66      ;;
    67    S)
    68      STREAM_ENGINE="analysis&mysql&localhost:3306,notify&redis&localhost:6379,kline&pulsar&localhost:6650"
    69      echo "$STREAM_ENGINE"
    70      ;;
    71    p)
    72      echo "IP=$OPTARG"
    73      IP=$OPTARG
    74      ;;
    75    \?)
    76      echo "Invalid option: -$OPTARG"
    77      ;;
    78    esac
    79  done
    80  
    81  echorun() {
    82    echo "------------------------------------------------------------------------------------------------"
    83    echo "["$@"]"
    84    $@
    85    echo "------------------------------------------------------------------------------------------------"
    86  }
    87  
    88  killbyname() {
    89    NAME=$1
    90    ps -ef|grep "$NAME"|grep -v grep |awk '{print "kill -9 "$2", "$8}'
    91    ps -ef|grep "$NAME"|grep -v grep |awk '{print "kill -9 "$2}' | sh
    92    echo "All <$NAME> killed!"
    93  }
    94  
    95  init() {
    96    killbyname ${BIN_NAME}
    97  
    98    (cd ${FBCHAIN_TOP} && make install VenusHeight=1)
    99  
   100    rm -rf cache
   101  
   102    echo "=================================================="
   103    echo "===== Generate testnet configurations files...===="
   104    echorun fbchaind testnet --v $1 --r $2 -o cache -l \
   105      --chain-id ${CHAIN_ID} \
   106      --starting-ip-address ${IP} \
   107      --base-port ${BASE_PORT} \
   108      --keyring-backend test
   109  }
   110  recover() {
   111    killbyname ${BIN_NAME}
   112    (cd ${FBCHAIN_TOP} && make install VenusHeight=1)
   113    rm -rf cache
   114    cp -rf nodecache cache
   115  }
   116  
   117  run() {
   118  
   119    index=$1
   120    seed_mode=$2
   121    p2pport=$3
   122    rpcport=$4
   123    restport=$5
   124    p2p_seed_opt=$6
   125    p2p_seed_arg=$7
   126  
   127    if [ "$(uname -s)" == "Darwin" ]; then
   128        sed -i "" 's/"enable_call": false/"enable_call": true/' cache/node${index}/fbchaind/config/genesis.json
   129        sed -i "" 's/"enable_create": false/"enable_create": true/' cache/node${index}/fbchaind/config/genesis.json
   130        sed -i "" 's/"enable_contract_blocked_list": false/"enable_contract_blocked_list": true/' cache/node${index}/fbchaind/config/genesis.json
   131    else
   132        sed -i 's/"enable_call": false/"enable_call": true/' cache/node${index}/fbchaind/config/genesis.json
   133        sed -i 's/"enable_create": false/"enable_create": true/' cache/node${index}/fbchaind/config/genesis.json
   134        sed -i 's/"enable_contract_blocked_list": false/"enable_contract_blocked_list": true/' cache/node${index}/fbchaind/config/genesis.json
   135    fi
   136  
   137    fbchaind add-genesis-account 0x28A9Bc244A5776cDAeFf6E646f0a368BAb344BD2 900000000fibo --home cache/node${index}/fbchaind
   138    fbchaind add-genesis-account 0x839868517f52263023F63222854698ceFD5D7217 900000000fibo --home cache/node${index}/fbchaind
   139    fbchaind add-genesis-account 0x9a80eB69b1E978474bF6b217B086271bD2C66923 900000000fibo --home cache/node${index}/fbchaind
   140    fbchaind add-genesis-account 0x692b5C42d871675B442e5CFc169e3A41d3F81620 900000000fibo --home cache/node${index}/fbchaind
   141    fbchaind add-genesis-account 0xE62209Dbf1a471804426B4E584eb28E8BD867AA5 900000000fibo --home cache/node${index}/fbchaind
   142  
   143  #  LOG_LEVEL=main:info,*:error,consensus:error,state:info
   144    LOG_LEVEL=main:info,iavl:info,*:error,state:info,provider:info,consensus:error,x/mint:debug
   145  
   146    echorun nohup fbchaind start \
   147      --home cache/node${index}/fbchaind \
   148      --p2p.seed_mode=$seed_mode \
   149      --p2p.allow_duplicate_ip \
   150      --dynamic-gp-mode=2 \
   151      --enable-wtx=${WRAPPEDTX} \
   152      --mempool.node_key_whitelist ${WHITE_LIST} \
   153      --p2p.pex=false \
   154      --p2p.addr_book_strict=false \
   155      $p2p_seed_opt $p2p_seed_arg \
   156      --p2p.laddr tcp://${IP}:${p2pport} \
   157      --rpc.laddr tcp://${IP}:${rpcport} \
   158      --log_level ${LOG_LEVEL} \
   159      --chain-id ${CHAIN_ID} \
   160      --upload-delta=false \
   161      --enable-gid \
   162      --consensus.timeout_commit 3800ms \
   163      --enable-blockpart-ack=false \
   164      --append-pid=true \
   165      ${LOG_SERVER} \
   166      --elapsed DeliverTxs=0,Round=1,CommitRound=1,Produce=1 \
   167      --rest.laddr tcp://localhost:$restport \
   168      --enable-preruntx=$PRERUN \
   169      --consensus-role=v$index \
   170      --active-view-change=true \
   171      ${Test_CASE} \
   172      --keyring-backend test >cache/val${index}.log 2>&1 &
   173  
   174  #     --iavl-enable-async-commit \    --consensus-testcase case12.json \
   175  #     --upload-delta \
   176  #     --enable-preruntx \
   177  #     --mempool.node_key_whitelist="nodeKey1,nodeKey2" \
   178  #    --mempool.node_key_whitelist ${WHITE_LIST} \
   179  }
   180  
   181  #prometheus_listen_addr
   182  #prof_laddr
   183  function start() {
   184    killbyname ${BIN_NAME}
   185    index=0
   186  
   187    echo "============================================"
   188    echo "=========== Startup seed node...============"
   189    ((restport = REST_PORT)) # for evm tx
   190    run $index true ${seedp2pport} ${seedrpcport} $restport
   191    seed=$(fbchaind tendermint show-node-id --home cache/node${index}/fbchaind)
   192  
   193    echo "============================================"
   194    echo "======== Startup validator nodes...========="
   195    for ((index = 1; index < ${1}; index++)); do
   196      ((p2pport = BASE_PORT_PREFIX + index * 100 + P2P_PORT_SUFFIX))
   197      ((rpcport = BASE_PORT_PREFIX + index * 100 + RPC_PORT_SUFFIX))  # for fbchaincli
   198      ((restport = index * 100 + REST_PORT)) # for evm tx
   199      run $index false ${p2pport} ${rpcport} $restport --p2p.seeds ${seed}@${IP}:${seedp2pport}
   200    done
   201    echo "start node done"
   202  }
   203  
   204  if [ -z ${IP} ]; then
   205    IP="127.0.0.1"
   206  fi
   207  
   208  if [ ! -z "${FBCHAIN_INIT}" ]; then
   209  	((NUM_VAL=NUM_NODE-NUM_RPC))
   210    init ${NUM_VAL} ${NUM_RPC}
   211  fi
   212  
   213  if [ ! -z "${FBCHAIN_RECOVER}" ]; then
   214    recover ${NUM_NODE}
   215  fi
   216  
   217  if [ ! -z "${FBCHAIN_START}" ]; then
   218    start ${NUM_NODE}
   219  fi