Commit 2632b315 authored by mdj33's avatar mdj33 Committed by vipwzw

add nginx to connect from paracross node to miner node

parent bbcf38d3
...@@ -23,6 +23,7 @@ NODE2="${1}_chain32_1" ...@@ -23,6 +23,7 @@ NODE2="${1}_chain32_1"
NODE1="${1}_chain31_1" NODE1="${1}_chain31_1"
NODE4="${1}_chain30_1" NODE4="${1}_chain30_1"
#CLI4="docker exec ${NODE4} /root/chain33-cli"
NODE5="${1}_chain29_1" NODE5="${1}_chain29_1"
CLI5="docker exec ${NODE5} /root/chain33-cli" CLI5="docker exec ${NODE5} /root/chain33-cli"
...@@ -99,7 +100,7 @@ function start() { ...@@ -99,7 +100,7 @@ function start() {
#docker-compose -f docker-compose.yml -f docker-compose-paracross.yml -f docker-compose-relay.yml up --build -d #docker-compose -f docker-compose.yml -f docker-compose-paracross.yml -f docker-compose-relay.yml up --build -d
docker-compose up --build -d docker-compose up --build -d
local SLEEP=30 local SLEEP=10
echo "=========== sleep ${SLEEP}s =============" echo "=========== sleep ${SLEEP}s ============="
sleep ${SLEEP} sleep ${SLEEP}
...@@ -111,26 +112,52 @@ function start() { ...@@ -111,26 +112,52 @@ function start() {
${CLI} net info ${CLI} net info
${CLI} net peer_info ${CLI} net peer_info
local count=100
while [ $count -gt 0 ]; do
peersCount=$(${CLI} net peer_info | jq '.[] | length') peersCount=$(${CLI} net peer_info | jq '.[] | length')
echo "${peersCount}" if [ "${peersCount}" -ge 2 ]; then
if [ "${peersCount}" -lt 2 ]; then break
sleep 20 fi
peersCount=$(${CLI} net peer_info | jq '.[] | length') sleep 5
echo "${peersCount}" ((count--))
if [ "${peersCount}" -lt 2 ]; then echo "peers error: peersCount=${peersCount}"
echo "peers error" done
miner "${CLI}"
block_wait "${CLI}" 1
echo "=========== check genesis hash ========== "
${CLI} block hash -t 0
res=$(${CLI} block hash -t 0 | jq ".hash")
count=$(echo "$res" | grep -c "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6")
if [ "${count}" != 1 ]; then
echo "genesis hash error!"
exit 1 exit 1
fi fi
echo "=========== query height ========== "
${CLI} block last_header
result=$(${CLI} block last_header | jq ".height")
if [ "${result}" -lt 1 ]; then
block_wait "${CLI}" 2
fi fi
sync_status "${CLI}"
${CLI} wallet status
${CLI} account list
${CLI} mempool list
}
function miner() {
#echo "=========== # create seed for wallet =============" #echo "=========== # create seed for wallet ============="
#seed=$(${CLI} seed generate -l 0 | jq ".seed") #seed=$(${1} seed generate -l 0 | jq ".seed")
#if [ -z "${seed}" ]; then #if [ -z "${seed}" ]; then
# exit 1 # exit 1
#fi #fi
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${1} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -139,7 +166,7 @@ function start() { ...@@ -139,7 +166,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${1} wallet unlock -p 1314 -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
...@@ -147,7 +174,7 @@ function start() { ...@@ -147,7 +174,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # import private key returnAddr =============" echo "=========== # import private key returnAddr ============="
result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label") result=$(${1} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
echo "${result}" echo "${result}"
if [ -z "${result}" ]; then if [ -z "${result}" ]; then
exit 1 exit 1
...@@ -156,7 +183,7 @@ function start() { ...@@ -156,7 +183,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # import private key mining =============" echo "=========== # import private key mining ============="
result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label") result=$(${1} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
echo "${result}" echo "${result}"
if [ -z "${result}" ]; then if [ -z "${result}" ]; then
exit 1 exit 1
...@@ -164,36 +191,12 @@ function start() { ...@@ -164,36 +191,12 @@ function start() {
sleep 1 sleep 1
echo "=========== # close auto mining =============" echo "=========== # close auto mining ============="
result=$(${CLI} wallet auto_mine -f 0 | jq ".isok") result=$(${1} wallet auto_mine -f 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
block_wait "${CLI}" 1
echo "=========== check genesis hash ========== "
${CLI} block hash -t 0
res=$(${CLI} block hash -t 0 | jq ".hash")
count=$(echo "$res" | grep -c "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6")
if [ "${count}" != 1 ]; then
echo "genesis hash error!"
exit 1
fi
echo "=========== query height ========== "
${CLI} block last_header
result=$(${CLI} block last_header | jq ".height")
if [ "${result}" -lt 1 ]; then
block_wait "${CLI}" 2
fi
sync_status "${CLI}"
${CLI} wallet status
${CLI} account list
${CLI} mempool list
} }
function block_wait() { function block_wait() {
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
echo "wrong block_wait params" echo "wrong block_wait params"
......
...@@ -465,8 +465,8 @@ func (client *client) RequestTx(seq *int64, preMainBlockHash *[]byte) ([]*types. ...@@ -465,8 +465,8 @@ func (client *client) RequestTx(seq *int64, preMainBlockHash *[]byte) ([]*types.
return txs, blockDetail.Block, seqTy, nil return txs, blockDetail.Block, seqTy, nil
} }
//not consistent case be processed at below //not consistent case be processed at below
plog.Error("RequestTx", "preMainHash", common.Bytes2Hex(*preMainBlockHash), "currSeq parentHash", common.Bytes2Hex(blockDetail.Block.ParentHash), plog.Error("RequestTx", "preMainHash", common.Bytes2Hex(*preMainBlockHash), "currSeq preMainHash", common.Bytes2Hex(blockDetail.Block.ParentHash),
"currSeq currentHash", common.Bytes2Hex(blockDetail.Block.Hash()), "curr seq", currSeq, "ty", seqTy, "currSeq Mainheight", blockDetail.Block.Height) "currSeq mainHash", common.Bytes2Hex(blockDetail.Block.Hash()), "curr seq", currSeq, "ty", seqTy, "currSeq Mainheight", blockDetail.Block.Height)
} }
//lastSeq < CurrSeq case: //lastSeq < CurrSeq case:
...@@ -484,6 +484,17 @@ func (client *client) RequestTx(seq *int64, preMainBlockHash *[]byte) ([]*types. ...@@ -484,6 +484,17 @@ func (client *client) RequestTx(seq *int64, preMainBlockHash *[]byte) ([]*types.
return nil, nil, -1, errors.New("hash not matched") return nil, nil, -1, errors.New("hash not matched")
} }
func (client *client) syncFromGenesisBlock(currSeq *int64, preMainBlockHash *[]byte) {
lastSeq, _, lastSeqMainHash, _, err := client.getLastBlockInfo()
if err != nil {
plog.Error("Parachain GetLastSeq fail", "err", err)
return
}
*currSeq = lastSeq + 1
*preMainBlockHash = lastSeqMainHash
plog.Info("syncFromGenesisBlock sync from height 0")
}
// search base on para block but not last MainBlockHash, last MainBlockHash can not back tracing // search base on para block but not last MainBlockHash, last MainBlockHash can not back tracing
func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[]byte) { func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[]byte) {
lastBlock, err := client.RequestLastBlock() lastBlock, err := client.RequestLastBlock()
...@@ -493,14 +504,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -493,14 +504,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
} }
//genesis block scenario, get new main node's blockHash as preMainHash, genesis sequence as currSeq //genesis block scenario, get new main node's blockHash as preMainHash, genesis sequence as currSeq
if lastBlock.Height == 0 { if lastBlock.Height == 0 {
lastSeq, _, lastSeqMainHash, _, err := client.getLastBlockInfo() client.syncFromGenesisBlock(currSeq, preMainBlockHash)
if err != nil {
plog.Error("Parachain GetLastSeq fail", "err", err)
return
}
*currSeq = lastSeq+1
*preMainBlockHash = lastSeqMainHash
plog.Error("switchHashMatchedBlock sync from height 0")
return return
} }
...@@ -514,8 +518,8 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -514,8 +518,8 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
if err != nil { if err != nil {
return return
} }
plog.Info("switchHashMatchedBlock", "lastBlock height", miner.Height, "mainheight", plog.Info("switchHashMatchedBlock", "lastParaBlock height", miner.Height, "mainHeight",
miner.MainBlockHeight, "mainhash", common.Bytes2Hex(miner.MainBlockHash)) miner.MainBlockHeight, "mainHash", common.Bytes2Hex(miner.MainBlockHash))
mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash) mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash)
if err != nil { if err != nil {
findDepth-- findDepth--
...@@ -532,14 +536,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -532,14 +536,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
*preMainBlockHash = nil *preMainBlockHash = nil
return return
} }
lastSeq, _, lastSeqMainHash, _, err := client.getLastBlockInfo() client.syncFromGenesisBlock(currSeq, preMainBlockHash)
if err != nil {
plog.Error("Parachain GetLastSeq fail", "err", err)
return
}
*currSeq = lastSeq+1
*preMainBlockHash = lastSeqMainHash
plog.Error("switchHashMatchedBlock sync from height 0")
return return
} }
continue continue
...@@ -554,7 +551,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -554,7 +551,7 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
*currSeq = mainSeq + 1 *currSeq = mainSeq + 1
*preMainBlockHash = miner.MainBlockHash *preMainBlockHash = miner.MainBlockHash
plog.Info("switchHashMatchedBlock succ", "currHeight", height, "lastHeight", lastBlock.Height, "set new currSeq", *currSeq, "new preMainBlockHash", common.Bytes2Hex(*preMainBlockHash)) plog.Info("switchHashMatchedBlock succ", "currHeight", height, "initHeight", lastBlock.Height, "set new currSeq", *currSeq, "new preMainBlockHash", common.Bytes2Hex(*preMainBlockHash))
return return
} }
} }
...@@ -581,7 +578,7 @@ func (client *client) removeBlocks(endHeight int64) error { ...@@ -581,7 +578,7 @@ func (client *client) removeBlocks(endHeight int64) error {
plog.Error("Parachain GetBlockedSeq fail", "err", err) plog.Error("Parachain GetBlockedSeq fail", "err", err)
return err return err
} }
plog.Error("Parachain removeBlocks succ", "localHeight", lastBlock.Height, "blockedSeq", blockedSeq) plog.Info("Parachain removeBlocks succ", "localParaHeight", lastBlock.Height, "blockedSeq", blockedSeq)
} }
} }
...@@ -627,8 +624,8 @@ func (client *client) CreateBlock() { ...@@ -627,8 +624,8 @@ func (client *client) CreateBlock() {
continue continue
} }
plog.Info("Parachain process block", "lastSeq", lastSeq, "curSeq", currSeq, plog.Info("Parachain process block", "lastBlockSeq", lastSeq, "curSeq", currSeq,
"lastSeqMainHeight", lastSeqMainHeight, "lastSeqMainHash", common.ToHex(lastSeqMainHash), "currSeqMainHeight", lastSeqMainHeight, "currSeqMainHash", common.ToHex(lastSeqMainHash),
"lastBlockMainHeight", lastBlockMainHeight, "lastBlockMainHash", common.ToHex(lastBlockMainHash)) "lastBlockMainHeight", lastBlockMainHeight, "lastBlockMainHash", common.ToHex(lastBlockMainHash))
if seqTy == delAct { if seqTy == delAct {
......
...@@ -72,7 +72,7 @@ maxTxNumPerAccount=10000 ...@@ -72,7 +72,7 @@ maxTxNumPerAccount=10000
name="para" name="para"
genesisBlockTime=1514533394 genesisBlockTime=1514533394
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt" genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
ParaRemoteGrpcClient = "localhost:8802" ParaRemoteGrpcClient="localhost:8802"
#主链指定高度的区块开始同步 #主链指定高度的区块开始同步
startHeight=345850 startHeight=345850
#打包时间间隔,单位秒 #打包时间间隔,单位秒
......
...@@ -5,6 +5,8 @@ services: ...@@ -5,6 +5,8 @@ services:
entrypoint: /root/entrypoint.sh entrypoint: /root/entrypoint.sh
environment: environment:
PARAFILE: "/root/chain33.para33.toml" PARAFILE: "/root/chain33.para33.toml"
expose:
- "8802"
chain32: chain32:
entrypoint: /root/entrypoint.sh entrypoint: /root/entrypoint.sh
...@@ -20,3 +22,16 @@ services: ...@@ -20,3 +22,16 @@ services:
entrypoint: /root/entrypoint.sh entrypoint: /root/entrypoint.sh
environment: environment:
PARAFILE: "/root/chain33.para30.toml" PARAFILE: "/root/chain33.para30.toml"
expose:
- "8802"
nginx:
image: nginx:latest
depends_on:
- chain33
- chain30
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
expose:
- "8803"
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 1000;
#gzip on;
upstream chain33url{
ip_hash;
server chain33:8802 weight=1;
#server chain30:8802 weight=1;
}
server {
listen 8803 http2;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#proxy_pass http://yankerp;
grpc_pass grpc://chain33url;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
...@@ -30,13 +30,14 @@ function para_set_toml() { ...@@ -30,13 +30,14 @@ function para_set_toml() {
sed -i $xsedfix 's/^Title.*/Title="user.p.'''$PARANAME'''."/g' "${1}" sed -i $xsedfix 's/^Title.*/Title="user.p.'''$PARANAME'''."/g' "${1}"
sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}" sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}"
sed -i $xsedfix 's/^startHeight=.*/startHeight=20/g' "${1}" sed -i $xsedfix 's/^startHeight=.*/startHeight=0/g' "${1}"
sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/g' "${1}" sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/g' "${1}"
# rpc # rpc
sed -i $xsedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g' "${1}" sed -i $xsedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g' "${1}"
sed -i $xsedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g' "${1}" sed -i $xsedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g' "${1}"
sed -i $xsedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' "${1}" sed -i $xsedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' "${1}"
sed -i $xsedfix 's/^ParaRemoteGrpcClient=.*/ParaRemoteGrpcClient="nginx:8803"/g' "${1}"
} }
function para_set_wallet() { function para_set_wallet() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment