# Add network to Delphinus Cross Chain without redeployment old networks This is a document about how to add network to the Delphinus system without redeployment old networks. This document use commits: https://github.com/DelphinusLab/delphinus-monitors/pull/54 https://github.com/DelphinusLab/delphinus-deployment/pull/28 https://github.com/DelphinusLab/delphinus-solidity/tree/addnetwork Assume the system is working well before adding new network and the new network is cantotestnet. ## Stop service **1. Stop ui** We want to add network, so user cannot operate on ui now. **2. Stop Indexer monitor** Ui is shutdown, so we do not need indexer monitor and history server now. **3. Stop History Server** **4. Stop l1 monitors** If we stop substrateNode before l1 monitors, l2 can not handle event(deposit, ack, etc.) **5. Stop substrateNode** **6. Stop l2 monitor** l2 monitor will save pending reqs event into mongoDB, so stop it before mongoDB **7. Stop Caddy** There are no service need to access reverse proxy now. **8. Stop mongoDB** ## Add new network * Add cantotestnet according to https://hackmd.io/xYKQyIGBRAOgAS3E-twbBA?view#Change-code-to-add-extra-network * In `solidity`, run `npx truffle migrate --network cantotestnet` * In `solidity/clients/`, run `node config-contracts-info.js` * In `solidity/clients/tools/bridge/`, run `node modifyRootAndRid.js cantotestnet` to modify merkle_root and rid for new deployed bridge contract in order to match the merkle_root and rid of pre-exist network * In `solidity/clients/tools/bridge/`, run `node initForAddNetwork.js cantotestnet bsctestnet` to add new token to pre-existing network * Run `node status.js bsctestnet` and `node status.js cantotestnet` in `solidity/clients/tools/bridge/` * In `zkcross-backend-lerna`, run `node packages/monitors/src/tools/init_BlockHeight.js` to generated new block height for the new network * Upgrade l2 runtime(AckAdmins) 1. Run `bash generate-config.sh` in `substrate-node` 2. Increment the `spec_version` to specify the new runtime version. Modify `substrate-node/runtime/src/lib.rs`: ![](https://i.imgur.com/KV7voQr.png) 3. Run `DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f packages/substrate-node/Dockerfile` in `zkcross-backend-lerna` 4. Run `docker-compose -f docker-compose.yml up` in `zkcross-backend-lerna` 5. Run `cargo +nightly-2023-01-24 build --locked --release` to generate new build artifacts `node_swap_runtime.compact.wasm`. ![](https://i.imgur.com/bUBpPcF.png) Here I use `nightly-2023-01-24` because latest rustup nightly have bugs. Current l2's `substrate-node/Dockerfile`: ``` FROM docker.io/paritytech/ci-linux:production as builder WORKDIR /delphinuslab COPY . /delphinuslab ENV CARGO_HOME /delphinuslab/.cargo-home Run curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y && \ rustup toolchain install nightly-2023-01-24 --force && \ rustup target add wasm32-unknown-unknown --toolchain nightly-2023-01-24 && \ rustup default nightly-2023-01-24 RUN --mount=type=cache,target=/delphinuslab/.cargo-home \ --mount=type=cache,target=/delphinuslab/packages/substrate-node/target \ cargo +nightly-2023-01-24 build --manifest-path=/delphinuslab/packages/substrate-node/Cargo.toml --locked --release && install -Dt ./bin/ /delphinuslab/packages/substrate-node/target/release/node-swap # This is the 2nd stage: a very small image where we copy the delphinuslab node binary." FROM docker.io/library/ubuntu:20.04 LABEL description="Zhenxunge node" COPY --from=builder /delphinuslab/bin/ /usr/local/bin/ RUN useradd -m -u 1000 -U -s /bin/sh -d /delphinuslab delphinuslab && \ mkdir -p /data /delphinuslab/.local/share && \ chown -R delphinuslab:delphinuslab /data /delphinuslab && \ ln -s /data /delphinuslab/.local/share/node-swap && \ # Sanity checks /usr/local/bin/node-swap --version USER delphinuslab # Insert session key 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 EXPOSE 30333 9933 9944 9615 VOLUME ["/data"] ENTRYPOINT ["/usr/local/bin/node-swap"] CMD ["--dev", "--ws-external"] ``` 6. Visit https://polkadot.js.org/apps/ and switch to local node ![](https://i.imgur.com/4GjDjWm.png) 6.1 Install https://polkadot.js.org/extension/ and create new accounts. use `import account from pre-existing seed` option to add new account. existing 12 or 24-word mnemonic seed: `bottom drive obey lake curtain smoke basket hold race lonely fit walk` Network: `Allow use on any chain` advanced/derivation path: `//Smith`, `//Frank` and `//Cindy//stash` A descriptive name for your account: I suggest using `Smith` for `//Smith`, `Frank` for `//Frank`, etc. 6.2 Click **Developer** and select **Extrinsics** to submit a transaction for the runtime to use the new build artifact. 6.3 Select the administrative **Smith** account. `Smith` is descriptive name for `//Smith` 6.4 Select the **sudo** pallet and the **sudoUncheckedWeight(call, weight)** function. 6.5 Select **system** and **setCode(code)** as the call to make using the `Smith` account. 6.6 Click **file upload**, then select or drag and drop the compact and compressed WebAssembly file—node_swap_runtime.compact.wasm—that you generated for the updated runtime. For example, navigate to the ·target/release/wbuild/node-template-runtime· directory and select `node_swap_runtime.compact.wasm` as the file to upload. 6.7 Leave both of the weight parameters set to the default value of 0. 6.8 Click Submit Transaction. 6.9 Review the authorization, then click **Sign and Submit**. After the transaction is included in a block, the node template version number indicates that the runtime version is now 101. ![](https://i.imgur.com/xlS96tD.png) * Add balance to new l2Account new l2Account need balance to setkey and addpool later. 1. In https://polkadot.js.org/apps/, click **Accounts** and select **Accounts** ![](https://i.imgur.com/gWzousF.png) You can see `//Cindy//stash`'s balance is 0 2. ![](https://i.imgur.com/LsFbjYa.png) 3. Click **Developer** and select **Extrinsics** 4. Select the administrative **Smith** account. `Smith` is descriptive name for `//Smith` 5. Select the **sudo** pallet and the **sudo(call)** function. 6. Select **balances** and **setBalance(who, newFree, newReserved)** as the call to make using the `Smith` account. `Cindy//stash` for `who: LookupSource` newFree: Compact<Balance>: 1000000unit = 1munit newReserved: Compact<Balance>: actually you can set it to zero 7. Click **Submit Transaction**. 8. Review the authorization, then click **Sign and Submit**. After the transaction is included in a block, `Cindy//stash` has balance now. ## Start service **1. Start Caddy** In `zkcross-lerna/`, run: ``` sudo caddy run --config ./Caddyfile ``` **2. Run mongodb** In `zkcross-learna/`, run: ``` mongod --dbpath [DB_PATH_NAME] ``` **3. Start l2 monitors** In `monitors/`, run: ``` sh run_l2monitor.sh -n // normal mode sh run_l2monitor.sh -v // verbose mode ``` `sh run_l2monitor.sh` is normal mode, too. **4. Start l1 monitors** In `monitors/`, run: ``` sh run_l1monitor.sh goerli sh run_l1monitor.sh bsctestnet sh run_l1monitor.sh cronostestnet sh run_l1monitor.sh rolluxtestnet ``` **5. Start Indexer monitor** In `monitors/`, run ``` bash run_indexer.sh ``` **6. Start History Server** In `deployment`, run: ``` npm run server ``` **7. Start ui** In "ui", run: ``` npm run start ``` Now you add new network to the system and the system can work.