# Replace network of Delphinus Cross Chain System
This is a document about how to replace network of Delphinus Cross Chain system.
Assume we want to replace the pre-existing network `cantotestnet` with a new network `newtestnet`.
# Summary
## Change points:
### BE
1. Modify `monitor-secrets.json`, `wallet-secrets.json`, `contractsinfo.ts` and `eth-config.ts` in the step [Modify `deployment/config/monitor-secrets.json`, `deployment/config/wallet-secrets.json`, `deployment/config/contractsinfo.ts` and `deployment/config/eth-config.ts`](https://hackmd.io/LerHXlqDTVW8dfDq6smqbg?view#3-Modify-deploymentconfigmonitor-secretsjson-deploymentconfigwallet-secretsjson-deploymentconfigcontractsinfots-and-deploymentconfigeth-configts).
2. Modify `init_bridge.sh`, `config-contracts-info.ts` and `truffle-config.js` in the step [Deploy layer1 contracts](https://hackmd.io/LerHXlqDTVW8dfDq6smqbg?view#5-Deploy-layer1-contracts). We also need to replace cronos with canto in the substep `Use tool to check we have enough eth for the testnetworks` and `Deploy contracts`.
3. Replace `sh run_l1monitor.sh cantotestnet` with `sh run_l1monitor.sh newtestnet` in the step [Run monitors](https://hackmd.io/LerHXlqDTVW8dfDq6smqbg?view#11-Run-monitors).
### FE
1. Replace the directory `deployment/config` with `deployment/config` in back end in the step [Modify deployment’s config](https://hackmd.io/LerHXlqDTVW8dfDq6smqbg?view#2-Modify-deployment%E2%80%99s-config)
### Notes:
1. We need change the config in all delphinus-deployment, delphinus-backend-deployment-template, delphinus-ui-deployment-template as currently client is using template repo to do the setting.
# Detail steps:
## Deploy backend
### Modules which will be installed and deployed
* Caddy
* Substrate Node
* mongoDB
* L1 and L2 monitors
* History Server
* Indexer monitor
### 1. Environment preparing
```
1. git clone git@github.com:zkcrossteam/zkcross-backend-lerna.git
2. cd zkcross-backend-lerna
3. bash environment_linux.sh
4. restart your shell to update environment variable (such as rustup)
// wasm-pack will not be installed if rust is not updated
// run bash environment_linux.sh if needed
5. bash setup-backend.sh
6. bash redobootstrap.sh
```
Step 3 and 4 can be skiped if the machine was deployed before as environment had been setup correctly.
### 2. Setup zkp and get verifier contract
*1. Generate ptau files.*
In `packages/zkp/circom`, run:
```
bash tools/setup.sh
```
This will take hours (maybe 24 hours). Instead after the first tiem you get the pot23_final.ptau file, you can save it and next time you can copy it to zkp/circom folder and do step 2 directly.
*2. Generate `verifier.sol`*
In `zkp/circom`, run:
```
bash tools/compile.sh
```
### 3. Modify `deployment/config/monitor-secrets.json`, `deployment/config/wallet-secrets.json`, `deployment/config/contractsinfo.ts` and `deployment/config/eth-config.ts`
#### Fill IDs and deployer priv_key of your own account in `deployment/config/monitor-secrets.json`
```
{
"ankr_id":"",
"infura_id_goerli":"",
"getblock_key_bsctestnet":"",
"getblock_key_goerli":"",
"accounts": {
"deployer": {
"priv": "" // update here
},
"tester": {
"priv":""
},
"tester2": {
"priv":""
},
"monitor": {
"priv":""
}
}
}
```
#### Replace `cantotestnet` with `newtestnet` in `deployment/config/wallet-secrets.json`
```
"rpcSources": {
"bsctestnet": "https://rpc.ankr.com/bsc_testnet_chapel",
"goerli": "https://rpc.ankr.com/eth_goerli",
"newtestnet": "",
"rolluxtestnet": "https://testnet.rollux.com:2814/"
}
```
Empty string is rpcSource of `newtestnet`.
#### Replace `cantotestnet` with `newtestnet` in `deployment/config/contractsinfo.ts`
```
export const Chains : Record<string, string> = {
"15": "local-test-net1",
"16": "local-test-net2",
"5": "goerli",
"97": "bsctestnet",
"": "newtestnet",
"2814": "rolluxtestnet"
}
```
Empty string is chainId of `newtestnet`.
Maybe you want to add `usdt/usdc` in `extraTokens`:
```
export const extraTokens = [
{
chainId: "97",
name: "usdt",
wei: 18,
address: "337610d27c682E347C9cD60BD4b3b107C9d34dDd"
},
{
chainId: "97",
name: "usdc",
wei: 18,
address: "64544969ed7EBf5f083679233325356EbE738930"
},
{
chainId: "5",
name: "usdt",
wei: 6,
address: "c81c248c44e96D85a0eCddc104843cE55B1ff35c"
},
{
chainId: "5",
name: "usdc",
wei: 6,
address: "07865c6E87B9F70255377e024ace6630C1Eaa37F"
},
{
chainId: "",
name: "usdt",
wei: ,
address: ""
},
{
chainId: "",
name: "usdc",
wei: ,
address: ""
}
]
```
Then run `npx tsc` to compile the modified `contractsinfo.ts`.
#### Change monitor account and network config in `deployment/config/eth-config.ts`
*<1>. Change all monitorAccount address to your own monitor accounts. (all deploy/withdraw transaction fee will be consumed from this account).*
*<2>. Replace `cantotestnet` with `newtestnet`*
replace
```
{
chainName: "cantotestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "20",
nativeCurrency: {
name: "Test Canto",
symbol: "Canto", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://testnet-explorer.canto.neobase.one/",
rpcSource: "https://eth.plexnode.wtf/",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "",
deviceId: "740",
l2Account: "//Cindy//stash",
enabled: testnet,
isSnap: false,
}
```
with
```
{
chainName: "newtestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "20",
nativeCurrency: {
name: "",
symbol: "", // 2-6 characters long
decimals: 18,
},
blockExplorer: "",
rpcSource: "",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "",
deviceId: "",
l2Account: "//Cindy//stash",
enabled: testnet,
isSnap: false,
}
```
There are many `""` in the config above, you should find them from official website of the new network. Set `wsSource` to `""` if the new network does not have a wsSource.
Then run `npx tsc` to compile the modified `eth-config.ts`.
### 4. Start Caddy
If you want to run Substrate node on **remote host**. A remote Substrate node can be accessible only after we set up a secure proxy for websocket connections. The TLS certificate is obtained automatically with Caddy.
*<1> Install Caddy (can skip if caddy had been installed)*
```
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
```
*<2> Add a file named "Caddyfile" to directory `zkcross-backend-lerna`*
```
{
auto_https disable_redirects
}
test.example.com:9944 {
reverse_proxy 127.0.0.1:9966
}
test.example.com:8090 {
reverse_proxy 127.0.0.1:8091
}
```
*<3> Start Caddy*
```
sudo caddy run --config ./Caddyfile
```
***If we are using `127.0.0.1` for local testing, caddy can be ignored.***
### 5. Deploy layer1 contracts
***Tips1: if following command not working properly because of rpcSources, you can check this:*** [Here](https://hackmd.io/xYKQyIGBRAOgAS3E-twbBA#Change-rpcSource-of-the-system-for-deployment)
***Tips2: if following command not working properly because of Monitor Accout, you can check this:*** [Here](https://hackmd.io/xYKQyIGBRAOgAS3E-twbBA#Change-Credential-of-the-system)
*<0>. Modify `init_bridge.sh`*
In `zkcross-backend-lerna/init_bridge.sh`, replace `cantotestnet` with `newtestnet`:
```
set -e
if [ ! -f initbridge.lock ];
then
cp packages/zkp/circom/verifier.sol packages/solidity/contracts/ZKPVerifier.sol
sed -i "s/\^0.6.11/^0.8.0/" packages/solidity/contracts/ZKPVerifier.sol
node packages/monitors/src/tools/init_BlockHeight.js
cd packages/solidity
npx truffle migrate --f 2 --to 2 --network goerli
npx truffle migrate --f 2 --to 2 --network bsctestnet
npx truffle migrate --f 2 --to 2 --network newtestnet
npx truffle migrate --f 2 --to 2 --network rolluxtestnet
cd -
cd packages/solidity/clients/
node config-contracts-info.js
cd -
cd packages/solidity/clients/tools/bridge
node init.js goerli
node init.js bsctestnet
node init.js newtestnet
node init.js rolluxtestnet
cd -
touch initbridge.lock
fi
echo "please start monitors"
```
*<1>. Modify `config-contracts-info.ts`*
In `solidity/clients/config-contracts-info.ts`, replace chainId of `cantotestnet` "740" with chainId of `newtestnet`:
```
{
chainId: "",
address: TokenInfo.networks[""]?.address.replace("0x", ""),
wei:18,
name:"tToken"
}
```
Then run `npx tsc` to compile the modified `config-contracts-info.ts`.
*<2>. Modify `truffle-config.js`*
In `solidity/truffle-config.js`, replace `cantotestnet` with `newtestnet`:
```
newtestnet: {
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider("")),
network_id: ,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
}
```
`network_id` is chainId of `newtestnet`.
argument of `http_provider` is `rpcSource` of `newtestnet`.
You can also replace
```
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider("https://"))
```
with the wsSource of `newtestnet`:
```
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
"wss://")
```
*<3>. Use tool to check we have enough eth for the testnetworks*
In `zkcross-backend-lerna/`, run:
`node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js goerli`
`node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js bsctestnet`
`node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js newtestnet`
`node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js rolluxtestnet`
*<4>. Deploy contracts*
*<4.1> If it is the first time to use `newtestnet`*
In `zkcross-backend-lerna/`, run:
```
cp packages/zkp/circom/verifier.sol packages/solidity/contracts/ZKPVerifier.sol
sed -i "s/\^0.6.11/^0.8.0/" packages/solidity/contracts/ZKPVerifier.sol
node packages/monitors/src/tools/init_BlockHeight.js
cd packages/solidity
npx truffle migrate --f 2 --to 2 --network goerli
npx truffle migrate --f 2 --to 2 --network bsctestnet
npx truffle migrate --network newtestnet
npx truffle migrate --f 2 --to 2 --network rolluxtestnet
cd -
cd packages/solidity/clients/
node config-contracts-info.js
cd -
cd packages/solidity/clients/tools/bridge
node init.js goerli
node init.js bsctestnet
node init.js newtestnet
node init.js rolluxtestnet
cd -
```
*<4.2> If it is not the first time to use `newtestnet`*
In `zkcross-backend-lerna/`, run `bash init_bridge.sh` (If your network is not that stable, normally we manually run each line inside).
### 6. Confirm onchain status
```
node packages/solidity/clients/tools/bridge/status.js chainName
```
### 7. Check l1 deployment succeed
```
node packages/solidity/clients/tools/bridge/validate_l1_deployment.js
```
### 8. Modify `deployment/config/substrate-node.json`
According to configs in `zkcross-backend-lerna/docker-compose.yml`:
Substrate node default to websocket connection: port 9944 on localhost. We bind port 9944 of the docker container "delphinus-node" to port 9966 on 127.0.0.1 of the host machine, then caddy expose it to 9944 on local caddy.
*<1>. Access Substrate node on remote host or local caddy with domain name*
Assume `test.example.com` is pointed to remote host on which the node is deployed.
*Modify `packages/deployment/config/substrate-node.json` to:*
```
{
"local_address": "ws://127.0.0.1",
"address": "wss://test.example.com",
"port": "9944"
}
```
port is set to 9944 because of the setting in Caddyfile
### 9. Deploy Substrate node
*<0>. Stop docker container and delete images*
**Tips**: docker builder may take huge disk space. `docker system df` can show the usage. If there are huge amount of disk space used by build cache, we can clean it by `docker builder prune -a`.
```
docker ps -a
docker rm [container id]
docker ps -a
docker volume ls
docker volume rm [volume name]
docker volume ls
docker image ls
docker image rm [repository name]
docker image ls
```
*Alternatively, you can clear the entire docker system (images, containers, networks and volumes) by using `docker system prune -a --volumes`*
***Customize tips:***
Ignore this if you would like to use default config
* If you want to customize l2 accounts, please check [here](https://hackmd.io/xYKQyIGBRAOgAS3E-twbBA#Custom-l2-account)
* If you want to set another authorities_seeds, please check [here](https://hackmd.io/xYKQyIGBRAOgAS3E-twbBA#Set-authorities_seeds)
*<1>. Apply custom account to substrate-node repo*
Run following command in `substrate-node`
```
bash generate-config.sh
```
*<2>. Check if Accounts and Admins configs have been added successfully*
Run following command in `substrate-node`
```
bash config-check.sh
```
*<3>. Compile and generate docker image*
In `zkcross-backend-lerna` folder, run:
```
DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f packages/substrate-node/Dockerfile
```
*<4>. Run the docker image in directory `zkcross-backend-lerna`*
```
docker-compose -f docker-compose.yml up
```
**If you haven't start Caddy, please start it now.**
*<5>. Setkey and addPool in l2*
```
node packages/monitors/src/tools/init-substrate.js
```
### 10. Run mongodb
*<0>. Clear mongodb*
```
cd [DB_PATH_NAME]
rm -r *
```
*<1>. Start mongodb*
```
mongod --dbpath [DB_PATH_NAME]
```
### 11. Run monitors
*<1>. Start l1 monitors. Replace `cantotestnet` with `newtestnet` in `monitors`, run:*
```
sh run_l1monitor.sh goerli
sh run_l1monitor.sh bsctestnet
sh run_l1monitor.sh newtestnet
sh run_l1monitor.sh rolluxtestnet
```
*<2>. Start l2 monitor. In `monitors`, run:*
```
sh run_l2monitor.sh -n // normal mode
sh run_l2monitor.sh -v // verbose mode
```
*`sh runl2monitor.sh` is normal mode, too.*
### 12. Start Indexer monitor
*This is monitor to collect history info for UI*
<1>. To Start the indexer, run the following in `packages/monitors` repo
```
bash run_indexer.sh
```
*Tips: To Restart the indexer and clear the mongodb collection, please run*
bash run_indexer.sh new
*and this will clear the DB, and start checking from block number 1.*
### 13. Check L2 Deployed status
run `bash l2_deployed_check.sh`
### 14. Server for History
<0>. modify `packages/deployment/config/server.json`
```
{
"address": "https://test.example.com:8090",
"port": "8091"
}
```
*<1>. For remote host deployment, you must add this to the Caddyfile in `zkcross-backend-lerna` as the UI will query this address.*
```
test.example.com:8090 {
reverse_proxy 127.0.0.1:8091
}
```
*<2>. restart Caddy (Stop Caddy and run):*
```
sudo caddy run --config ./Caddyfile
```
*<3>. To start the server, from `deployment` run:*
Need change server.json first.
```
npm run server
```
## Deploy frontend
***backend need to be deployed and start first as we need grab info from backend.***
### 1. Environment preparing
```
1. git clone git@github.com:zkcrossteam/zkcross-frontend-lerna.git
2. cd zkcross-frontend-lerna
3. bash environment_linux.sh
4. bash setup-frontend.sh
5. Change UI repo branch to those you want deploy.(main or zkc).
6. bash redobootstrap.sh
```
### 2. Modify deployment's config
*<1>. Replace `deployment/config/contracts-info.json` with pre-saved json from back end. or checkout configs from new created branch from back end*
*<2>. Replace `deployment/config/substrate-node.json`* to match the back end.
*<3>. Replace `deployment/config/token-index.json` to match the back end.*
*<4>. Modify `deployment/config/server.json` to match the back end.*
*<5>. Modify `deployment/config/eth-config.ts` to match the back end and run `npx tsc` in `deployment`.*
### 3. Set Server URL/Address
For UI to query L2 transaction history and fetch contract information from the history server which will be deployed on the backend host, modify `deployment/config/server.json`:
1. If the server is deployed on a remote host with domain name
The address must be changed to your server URL which is used by Caddy. For example, `https://test.example.com:8090`
```
{
"address": "https://test.example.com:8090",
"port": "8090"
}
```
### 4. Set Substrate-Node URL/Address (Refine description as we had copy it from B/E)
For UI to read the substrate node address, modify `deployment/config/substrate-node.json`:
1. If your node is deployed on a remote host or locally with domain name
Assume test.example.com is pointed to remote host on which the node is deployed.
```
{
"local_address": "ws://127.0.0.1",
"address": `wss://test.example.com`
"port": "9944"
}
```
Here we set the port to 9944 according to `Caddyfile` of backend
### 5. Start the UI
**In `ui` repo:**
*<1>. run:*
`npm run start`
### 6. Access Delphinus user interface
**Local machine:**
Visit "http://localhost:3000" in the browser and do testing:
* Activate
* Charge
* Deposit
* WithDraw
* ...
Here is the document of Delphinus user interface: https://github.com/DelphinusLab/delphinus-training/blob/main/Documents/DelphinusUI.md.
## Additional Information:
### Change rpcSource of the system for deployment
If we run `node init.js` in the step [`Deploy layer1 contracts`](https://hackmd.io/LerHXlqDTVW8dfDq6smqbg?view#5-Deploy-layer1-contracts), the default rpcSource in `deployment/config/eth-config.ts` maybe unstable.
**1. Change `rpcSource` of `bsctestnet` in `deployment/config/eth-config.ts` to `https://data-seed-prebsc-1-s1.binance.org:8545` because rpcSource provided by ankr is unstable:**
```
{
chainName: "bsctestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "1",
nativeCurrency: {
name: "Test Binance Coin",
symbol: "tBNB", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://testnet.bscscan.com",
//rpcSource:
//"https://data-seed-prebsc-1-s1.binance.org:8545",
rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source.
wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "",
deviceId: "97",
l2Account: "//Smith",
enabled: testnet,
isSnap: false,
}
```
**2. Change `rpcSource` of `goerli` in `deployment/config/eth-config.ts` to `"https://goerli.infura.io/v3/" + secrets.infura_id_goerli` because rpcSource provided by ankr is unstable:**
If `rpcSource` is already infura, skip this step.
```
{
chainName: "goerli",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000, //default step 0: sync to latest directly
bufferBlocks: 0,
gasWarningAmount: "1",
nativeCurrency: {
name: "Goerli ETH",
symbol: "GoETH", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://goerli.etherscan.io",
rpcSource:
"https://goerli.infura.io/v3/" + secrets.infura_id_goerli,
wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli
//rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id,
//wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "",
deviceId: "5",
l2Account: "//Frank",
enabled: testnet,
isSnap: true,
}
```
If these address is still unstable, you should find other alternatives.
**After modifying eth-config.ts, do not forget to run `npx tsc` to compile typescript**
### Change Credential of the system
**1. In `deployment/config/eth-config.ts`, update `monitorAccount` of `bsctestnet`, `goerli`, `cantotestnet` and `rolluxtestnet`.** For example, this is the configure of `bsctestnet` and there is a key `monitorAccount`. Update `monitorAccount`'s value:
```
{
chainName: "bsctestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "1",
nativeCurrency: {
name: "Test Binance Coin",
symbol: "tBNB", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://testnet.bscscan.com",
//rpcSource:
//"https://data-seed-prebsc-1-s1.binance.org:8545",
rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source.
wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "", // update here
deviceId: "97",
l2Account: "//Smith",
enabled: testnet,
isSnap: false,
}
```
**After modifying eth-config.ts, do not forget to run `npx tsc` to compile typescript**
### Custom l2 account
You can **skip** this step if you would like to use **default** config.
**2.1. Modify `deployment/config/substrate-account-config.json`:**
```
{
"secret_key_uri": [
"//Smith",
"//Frank",
"//Cindy//stash",
"//Richard"
],
"authorities_seeds": [
"Eve//stash"
],
"pre_funded_seeds": [
"Smith",
"Frank",
"Cindy//stash",
"Richard"
],
"sudo_account_seed": "sudo"
}
```
**2.2 Modify `deployment/config/eth-config.js`**
Or modify `deployment/config/eth-config.ts` and run `npx tsc` in `deployment`
```
{
chainName: "bsctestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
rpcSource:
"https://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key,
wsSource:
"wss://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556",
deviceId: "97",
l2Account: "//Smith",
enabled: testnet,
isSnap: false,
},
{
chainName: "goerli",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000, //default step 0: sync to latest directly
gasWarningAmount: "1",
rpcSource:
"https://goerli.infura.io/v3/" + secrets.infura_id_goerli,
wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli
//rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id,
//wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556",
deviceId: "5",
l2Account: "//Frank",
enabled: testnet,
isSnap: true,
},
{
chainName: "cantotestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "20",
nativeCurrency: {
name: "Test Canto",
symbol: "Canto", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://testnet-explorer.canto.neobase.one/",
rpcSource: "https://eth.plexnode.wtf/",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556",
deviceId: "740",
l2Account: "//Cindy//stash",
enabled: testnet,
isSnap: false,
},
{
chainName: "rolluxtestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 20000,
rpcSource: "https://testnet.rollux.com:2814/",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556",
deviceId: "2814",
l2Account: "//Richard",
enabled: testnet,
isSnap: true,
}
```
### Set authorities_seeds
Change `//Eve//stash` to `authorities_seeds` in `step 2.1` in `substrate-node/Dockerfile`:
```
RUN /usr/local/bin/node-swap key insert --chain dev --scheme Ed25519 --suri //Eve//stash --key-type gran && \
/usr/local/bin/node-swap key insert --chain dev --scheme Sr25519 --suri //Eve//stash --key-type aura
```
**Note**: need add "//" before `authorities_seeds`(Eve//stash).
### Change code to add extra network
Assume extra network is exampletestnet
**1. Modify `delphinus-lerna/init_bridge.sh` to**
```
set -e
if [ ! -f initbridge.lock ];
then
cp packages/zkp/circom/verifier.sol packages/solidity/contracts/ZKPVerifier.sol
sed -i "s/\^0.6.11/^0.8.0/" packages/solidity/contracts/ZKPVerifier.sol
# Dont have to migrate the tokens again
cd packages/solidity
npx truffle migrate --f 2 --to 2 --network goerli
npx truffle migrate --f 2 --to 2 --network bsctestnet
npx truffle migrate --f 2 --to 2 --network cantotestnet
npx truffle migrate --f 2 --to 2 --network rolluxtestnet
npx truffle migrate --f 2 --to 2 --network exampletestnet
cd -
cd packages/solidity/clients/
node config-contracts-info.js
cd -
cd packages/solidity/clients/tools/bridge
node init.js goerli
node init.js bsctestnet
node init.js cantotestnet
node init.js rolluxtestnet
node init.js exampletestnet
cd -
touch initbridge.lock
fi
echo "please start monitors"
```
**2. Insert a new config in `networks` in `solidity/truffle-config.js`**
```
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
gas: 3100000, // Gas sent with each transaction (default: ~6700000)
websocket: true // Enable EventEmitter interface for web3 (default: false)
},
testnet1: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
gas: 3100000, // Gas sent with each transaction (default: ~6700000)
websocket: true // Enable EventEmitter interface for web3 (default: false)
},
testnet2: {
host: "127.0.0.1", // Localhost (default: none)
port: 8745, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
gas: 3100000, // Gas sent with each transaction (default: ~6700000)
websocket: true // Enable EventEmitter interface for web3 (default: false)
},
goerli: { //eth testnet
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider("https://eth.getblock.io/goerli/?api_key=" + secrets.getblock_key_goerli)
),
network_id: 5, // goerli's id
gas: 5500000, // goerli has a lower block limit than mainnet
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 400, // # of blocks before a deployment times out (minimum/default: 50)
skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
},
bsctestnet: { //bsc
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider(`https://data-seed-prebsc-1-s1.binance.org:8545`)
//http_provider("https://bsc.getblock.io/testnet/?api_key="+secrets.getblock_key)
),
network_id: 97,
confirmations: 10,
timeoutBlocks: 200,
skipDryRun: true
},
cantotestnet: {
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider("https://eth.plexnode.wtf/")),
network_id: 740,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
rolluxtestnet: {
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
http_provider("https://testnet.rollux.com:2814/")),
network_id: 2814,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
exampletestnet: {
provider: () => new HDWalletProvider(secrets.accounts.deployer.priv,
""),
network_id:,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
}
```
You will find 5 objects in `networks` of files in `solidity/build/contracts` after `npx truffle migrate`.
(Of course you will find empty networks if `solidity/migrations` does not deploy the contract)

**3. Insert a new config in `solidity/clients/config-contracts-info.js`**
```
tokens: [
{
chainId: "15",
address: (_a = TokenInfo.networks["15"]) === null || _a === void 0 ? void 0 : _a.address.replace("0x", ""),
wei: 12,
name: "tToken"
},
{
chainId: "16",
address: (_c = TokenInfo.networks["16"]) === null || _c === void 0 ? void 0 : _c.address.replace("0x", ""),
wei: 12,
name: "sToken",
},
{
chainId: "5",
address: (_d = TokenInfo.networks["5"]) === null || _d === void 0 ? void 0 : _d.address.replace("0x", ""),
wei: 12,
name: "tToken"
},
{
chainId: "97",
address: (_f = TokenInfo.networks["97"]) === null || _f === void 0 ? void 0 : _f.address.replace("0x", ""),
wei: 12,
name: "tToken"
},
{
chainId: "740",
address: (_g = TokenInfo.networks["740"]) === null || _g === void 0 ? void 0 : _g.address.replace("0x", ""),
wei: 12,
name: "tToken"
},
{
chainId: "2814",
address: (_h = TokenInfo.networks["2814"]) === null || _h === void 0 ? void 0 : _h.address.replace("0x", ""),
wei: 12,
name: "tToken"
},
{
chainId: "",
address: (_h = TokenInfo.networks[""]) === null || _h === void 0 ? void 0 : _h.address.replace("0x", ""),
wei: 12,
name: "tToken"
}
]
```
**Add name for new testnet in `solidity/clients/config-contracts-info.ts`:**
```
export const Chains : Record<string, string> = {
"15": "local-test-net1",
"16": "local-test-net2",
"5": "goerli",
"97": "bsctestnet",
"740": "cantotestnet",
"2814": "rolluxtestnet"
"chainNumber": "exampletestnet"
}
```
**4. Add new seed into `deployment/config/substrate-account-config.json`**
```
{
"secret_key_uri": [
"//Smith",
"//Frank",
"//Cindy//stash",
"//Richard",
"//exampleAccount"
],
"authorities_seeds": [
"Eve//stash"
],
"pre_funded_seeds": [
"Smith",
"Frank",
"Cindy//stash",
"/Richard",
"exampleAccount"
],
"sudo_account_seed": "sudo"
}
```
**5. Add new config into `deployment/config/eth-config.js`**
```
{
chainName: "bsctestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
rpcSource:
"https://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key,
wsSource:
"wss://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
deviceId: "97",
l2Account: "//Smith",
enabled: testnet,
isSnap: false,
},
{
chainName: "goerli",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000, //default step 0: sync to latest directly
gasWarningAmount: "1",
rpcSource:
"https://goerli.infura.io/v3/" + secrets.infura_id_goerli,
wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli
//rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id,
//wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id,
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0x6f6eF6Dfe681b6593Ddf27da3BfDe22083AEF88b",
deviceId: "5",
l2Account: "//Frank",
enabled: testnet,
isSnap: true,
},
{
chainName: "cantotestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 2000,
bufferBlocks: 0,
gasWarningAmount: "20",
nativeCurrency: {
name: "Test Canto",
symbol: "Canto", // 2-6 characters long
decimals: 18,
},
blockExplorer: "https://testnet-explorer.canto.neobase.one/",
rpcSource: "https://eth.plexnode.wtf/",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
deviceId: "740",
l2Account: "//Cindy//stash",
enabled: testnet,
isSnap: false,
},
{
chainName: "rolluxtestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 20000,
rpcSource: "https://testnet.rollux.com:2814/",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
deviceId: "2814",
l2Account: "//Richard",
enabled: testnet,
isSnap: true,
},
{
chainName: "exampletestnet",
mongodbUrl: "mongodb://localhost:27017",
syncEventsStep: 20000,
rpcSource: "",
wsSource: "",
privateKey: secrets.accounts.deployer.priv,
monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b",
deviceId: "",
l2Account: "//exampleAccount",
enabled: testnet,
isSnap: true,
}
```
**Explanations**
**1. Explanation to keys in config**
* `secret_key_uri` is seed of `admins` in `substrate-node/runtime/admins_config.rs`. Only `secret_key_uri` has prefix "//".
* `authorities_seeds` is accounts having authority to create and finalize blocks. Be sure to use unique seeds in this field. If two validators have the same keys, they produce conflicting blocks.
* `l2Account` in `deployment/config/eth-config.js` is `origin` of functions in `substrate-node/pallets/swap`. `l2Account` must have enough balance to invoke functions in l2, so we should add it to `pre_funded_seeds`. **Do not set same `l2Account`** for different networks otherwise we don't know which l1 network is the origin of funtions in l2.
* `sudo_account_seed` is the account we use to execute functions that require a Root call. Only one account can be the sudo key at a time.
* `secret_key_uri`, `pre_funded_seeds`, and `l2Account` must be the same. Third party is not allowed to invoke functions such as `add_pool`.
* `//Smith` in `secret_key_uri` is the same as `Smith` in `pre_funded_seeds` because input of `keyring.addFromUri`(line 85 of `monitors/src/substrate/client.ts`) and `get_from_seed`(line 22 of `substrate-node/node/src/chain_spec.rs`)/`get_account_id_from_seed`(line 31 of `substrate-node/node/src/chain_spec.rs`) is different.

* You can use two seeds form: `//Alice` or `//Alice//stash`. **Do not use** `//Alice/stash` which is not supported by chain specification of substrate node.
* Block finalization requires at least **two-thirds of the validators** to add their keys to their respective keystores. For example, if there are 4 seeds in `authorities_seeds`, you should add `key insert` in `Dockerfile` and run at least 3(4 * 2 / 3) nodes.
**2. Explanation to `/usr/local/bin/node-swap key insert --chain dev --scheme Ed25519 --suri //Eve --key-type gran`**
* Session keys are used by validators to sign consensus-related messages. `key insert` will insert session keys to keystore.
* `--chain dev` specifies insert keys to keystore of dev mode.
* `--scheme` specifies signing algorithms(Ed25519 for grandpa and Sr25519 for aura).
* `--suri` specifies seed of key.
* `--key-type` specifies key type. The aura key type is required to enable block production. The gran key type is required to enable block finalization.
### How to add pools
#### Default pools after standard init
Add tToken in `config-contracts-info.ts` in `solidity/clients` folder
```
{
chainId: "***",
address:TokenInfo.networks["***"]?.address.replace("0x", ""),
wei:12,
name:"tToken"
}
```
#### How to add pools for extra token pair
Add extra token in `contractsinfo.ts` in `deployment/config` folder
```
{
chainId: "***",
name: "****",
wei: **,
address: "***************************"
}
```
### How to do deployment on feature branch
1. If lerna repo need feature branch, checkout feature branch first.
2. do `bash setup.sh`
3. go to the packages/[repo] folders and get the branch to the feature branch you want
4. got to the lerna root folder and do `bash redobootstrap.sh`
5. Then you can do the deployment as normal