forked from bnb-chain/zkbnb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-local.sh
283 lines (205 loc) · 8.41 KB
/
deploy-local.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# Preparation: Install following tools when you first run this script!!!
# GOBIN=/usr/local/bin/ go install github.com/zeromicro/go-zero/tools/goctl@latest
# yum install jq -y
# npm install pm2 -g
# You should install nodejs above v14
# Attention: Set the following variables to the right one before running!!!
DEPLOY_PATH=~/zkbnb-deploy
KEY_PATH=~/.zkbnb
ZkBNB_REPO_PATH=$(cd `dirname $0`; pwd)
CMC_TOKEN=cfce503f-fake-fake-fake-bbab5257dac8
BSC_TESTNET_PRIVATE_KEY=acbaa26******************************a88367d9
export PATH=$PATH:/usr/local/go/bin:/usr/local/go/bin:/root/go/bin
echo '0. stop old database/redis and docker run new database/redis'
pm2 delete all
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker run -d --name zkbnbredis -p 6379:6379 redis
docker run --name postgres -p 5432:5432 -e PGDATA=/var/lib/postgresql/pgdata -e POSTGRES_PASSWORD=ZkBNB@123 -e POSTGRES_USER=postgres -e POSTGRES_DB=zkbnb -d postgres
echo '1. basic config and git clone repos'
export PATH=$PATH:/usr/local/go/bin/
cd ~
rm -rf ${DEPLOY_PATH}-bak && mv ${DEPLOY_PATH} ${DEPLOY_PATH}-bak
mkdir -p ${DEPLOY_PATH} && cd ${DEPLOY_PATH}
git clone --branch develop https://github.com/bnb-chain/zkbnb-contract.git
git clone --branch develop https://github.com/bnb-chain/zkbnb-crypto.git
cp -r ${ZkBNB_REPO_PATH} ${DEPLOY_PATH}
flag=$1
if [ $flag = "new" ]; then
echo "new crypto env"
echo '2. start generate zkbnb.vk and zkbnb.pk'
cd ${DEPLOY_PATH}
cd zkbnb-crypto && go test ./circuit/solidity -timeout 99999s -run TestExportSol
cd ${DEPLOY_PATH}
mkdir -p $KEY_PATH
cp -r ./zkbnb-crypto/circuit/solidity/* $KEY_PATH
fi
echo '3. start verify_parse for ZkBNBVerifier'
cd ${DEPLOY_PATH}/zkbnb/service/prover/
python3 verifier_parse.py ${KEY_PATH}/ZkBNBVerifier10.sol 10 ${DEPLOY_PATH}/zkbnb-contract/contracts/ZkBNBVerifier.sol
echo '4-1. get latest block number'
hexNumber=`curl -X POST 'https://data-seed-prebsc-1-s1.binance.org:8545' --header 'Content-Type: application/json' --data-raw '{"jsonrpc":"2.0", "method":"eth_blockNumber", "params": [], "id":1 }' | jq -r '.result'`
blockNumber=`echo $((${hexNumber}))`
echo 'latest block number = ' $blockNumber
echo '4-2. deploy contracts, register and deposit on BSC Testnet'
cd ${DEPLOY_PATH}
cd ./zkbnb-contract && echo "BSC_TESTNET_PRIVATE_KEY=${BSC_TESTNET_PRIVATE_KEY}" > .env && yarn install
npx hardhat --network BSCTestnet run ./scripts/deploy-keccak256/deploy.js
echo 'Recorded latest contract addresses into ${DEPLOY_PATH}/zkbnb-contract/info/addresses.json'
npx hardhat --network BSCTestnet run ./scripts/deploy-keccak256/register.js
npx hardhat --network BSCTestnet run ./scripts/deploy-keccak256/deposit.js
echo '5. modify deployed contracts into zkbnb config'
cd ${DEPLOY_PATH}/zkbnb/tools/dbinitializer/
cp -r ./contractaddr.yaml.example ./contractaddr.yaml
ZkBNBContractAddr=`cat ${DEPLOY_PATH}/zkbnb-contract/info/addresses.json | jq -r '.zkbnbProxy'`
sed -i -e "s/ZkBNBProxy: .*/ZkBNBProxy: ${ZkBNBContractAddr}/" ${DEPLOY_PATH}/zkbnb/tools/dbinitializer/contractaddr.yaml
GovernanceContractAddr=`cat ${DEPLOY_PATH}/zkbnb-contract/info/addresses.json | jq -r '.governance'`
sed -i -e "s/Governance: .*/Governance: ${GovernanceContractAddr}/" ${DEPLOY_PATH}/zkbnb/tools/dbinitializer/contractaddr.yaml
BUSDContractAddr=`cat ${DEPLOY_PATH}/zkbnb-contract/info/addresses.json | jq -r '.BUSDToken'`
sed -i -e "s/BUSDToken: .*/BUSDToken: ${BUSDContractAddr}/" ${DEPLOY_PATH}/zkbnb/tools/dbinitializer/contractaddr.yaml
# cd ${DEPLOY_PATH}/zkbnb/
# make api-server
cd ${DEPLOY_PATH}/zkbnb && go mod tidy
echo "6. init tables on database"
go run ./cmd/zkbnb/main.go db initialize --dsn "host=localhost user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable" --contractAddr ${DEPLOY_PATH}/zkbnb/tools/dbinitializer/contractaddr.yaml
sleep 10s
echo "7. run prover"
echo -e "
Name: prover
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
KeyPath:
ProvingKeyPath: [${KEY_PATH}/zkbnb10.pk]
VerifyingKeyPath: [${KEY_PATH}/zkbnb10.vk]
BlockConfig:
OptionalBlockSizes: [10]
TreeDB:
Driver: memorydb
AssetTreeCacheSize: 512000
" > ${DEPLOY_PATH}/zkbnb/service/prover/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go prover --config ${DEPLOY_PATH}/zkbnb/service/prover/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6060 --metrics --metrics.addr 0.0.0.0 --metrics.port 6060
" > run_prover.sh
pm2 start --name prover "./run_prover.sh"
echo "8. run witness"
echo -e "
Name: witness
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
TreeDB:
Driver: memorydb
AssetTreeCacheSize: 512000
" > ${DEPLOY_PATH}/zkbnb/service/witness/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go witness --config ${DEPLOY_PATH}/zkbnb/service/witness/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6061 --metrics --metrics.addr 0.0.0.0 --metrics.port 6061
" > run_witness.sh
pm2 start --name witness "./run_witness.sh"
echo "9. run monitor"
echo -e "
Name: monitor
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
ChainConfig:
NetworkRPCSysConfigName: "BscTestNetworkRpc"
#NetworkRPCSysConfigName: "LocalTestNetworkRpc"
StartL1BlockHeight: $blockNumber
ConfirmBlocksCount: 0
MaxHandledBlocksCount: 5000
KeptHistoryBlocksCount: 100000
TreeDB:
Driver: memorydb
AssetTreeCacheSize: 512000
" > ${DEPLOY_PATH}/zkbnb/service/monitor/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go monitor --config ${DEPLOY_PATH}/zkbnb/service/monitor/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6062 --metrics --metrics.addr 0.0.0.0 --metrics.port 6062
" > run_monitor.sh
pm2 start --name monitor "./run_monitor.sh"
echo "10. run committer"
echo -e "
Name: committer
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
BlockConfig:
OptionalBlockSizes: [10]
TreeDB:
Driver: memorydb
AssetTreeCacheSize: 512000
" > ${DEPLOY_PATH}/zkbnb/service/committer/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go committer --config ${DEPLOY_PATH}/zkbnb/service/committer/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6063 --metrics --metrics.addr 0.0.0.0 --metrics.port 6063
" > run_committer.sh
pm2 start --name committer "./run_committer.sh"
echo "11. run sender"
echo -e "
Name: sender
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
ChainConfig:
NetworkRPCSysConfigName: "BscTestNetworkRpc"
#NetworkRPCSysConfigName: "LocalTestNetworkRpc"
ConfirmBlocksCount: 0
MaxWaitingTime: 120
MaxBlockCount: 4
Sk: "${BSC_TESTNET_PRIVATE_KEY}"
GasLimit: 5000000
GasPrice: 0
TreeDB:
Driver: memorydb
AssetTreeCacheSize: 512000
" > ${DEPLOY_PATH}/zkbnb/service/sender/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go sender --config ${DEPLOY_PATH}/zkbnb/service/sender/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6064 --metrics --metrics.addr 0.0.0.0 --metrics.port 6064
" > run_sender.sh
pm2 start --name sender "./run_sender.sh"
echo "12. run api-server"
echo -e "
Name: api-server
Host: 0.0.0.0
Port: 8888
TxPool:
MaxPendingTxCount: 10000
Postgres:
DataSource: host=127.0.0.1 user=postgres password=ZkBNB@123 dbname=zkbnb port=5432 sslmode=disable
MaxConn: 100
MaxIdle: 10
CacheRedis:
- Host: 127.0.0.1:6379
Type: node
LogConf:
ServiceName: api-server
Mode: console
Path: ./log/api-server
StackCooldownMillis: 500
Level: error
CoinMarketCap:
Url: https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=
Token: ${CMC_TOKEN}
MemCache:
AccountExpiration: 200
AssetExpiration: 600
BlockExpiration: 400
TxExpiration: 400
PriceExpiration: 3600000
MaxCounterNum: 100000
MaxKeyNum: 10000
" > ${DEPLOY_PATH}/zkbnb/service/apiserver/etc/config.yaml
echo -e "
go run ./cmd/zkbnb/main.go apiserver --config ${DEPLOY_PATH}/zkbnb/service/apiserver/etc/config.yaml --pprof --pprof.addr 0.0.0.0 --pprof.port 6065 --metrics --metrics.addr 0.0.0.0 --metrics.port 6065
" > run_apiserver.sh
pm2 start --name apiserver "./run_apiserver.sh"