# Run a Kabocha collator

Instructions for an operator's agent. Follow the steps in order and check each one before moving on. Everything here is public. Nothing in it is a secret.

Kabocha is parachain 2113 on Kusama. Today one collator makes its blocks, run by Birdbrain. We want at least three, run by different people on different machines. This kit sets up one more.

Files: https://kabocha-rpc.birdbrain.wtf/node/

| File | What |
| --- | --- |
| `SETUP.md` | This guide |
| `install.sh` | Installs and starts the node |
| `kabocha` | The node program, the 2022 Kabocha client (`0.1.0-e0031507a26`, Unlicense, source `github.com/kabocha-network/parachain` at commit `e0031507a265`) |
| `2113-raw.json` | The Kabocha chain spec |
| `relay-ungap-watch.sh` | First-sync disk guard, explained in step 3 |
| `SHA256SUMS` | Checksums for all of the above |

## 1. What the server needs

- x86_64 Linux. Tested on **Debian 12**. Other distributions may work but are untested.
- 4 vCPU, 8 GB RAM, 100 GB SSD. About 20 GB is used today, almost all of it the pruned Kusama node that runs inside the collator.
- A public IPv4 address. Inbound TCP **30333** (Kabocha peers) and **30334** (Kusama peers) open, on the server and on any cloud firewall in front of it.
- Its own machine. Do not share it with another collator.

## 2. Install

As root:

```bash
cd /root
curl -fsSLO https://kabocha-rpc.birdbrain.wtf/node/install.sh
curl -fsSLO https://kabocha-rpc.birdbrain.wtf/node/SHA256SUMS
grep ' install.sh$' SHA256SUMS | sha256sum -c -
NODE_NAME=<operator>-kabocha bash install.sh
```

`NODE_NAME` is a public label that other nodes see. Letters, digits, `-` and `_` only.

The script:

1. installs `curl` and `rocksdb-tools`
2. creates a `kabocha` system user and `/opt/kabocha/{bin,data,relay,tools}`
3. downloads the binary and chain spec and stops if a checksum fails
4. writes `kabocha.service` (the node) and `kabocha-ungap-watch.service` (the guard)
5. opens 30333 and 30334 if `ufw` is active
6. starts the guard on a first install, then the node

It is safe to run again. It never creates or touches an account key.

## 3. The disk trap (why the guard exists)

After a Kusama warp sync, this 2022 client starts downloading Kusama's entire block history even though pruning is on. On our box that added 37 GB in under two hours and filled the disk. The guard waits for the warp to finish, stops the node, deletes the block-history gap marker from the Kusama database with `ldb`, and restarts. It also stops the node if `/` passes 85% full.

Check it worked, about 15-60 minutes after install:

```bash
cat /opt/kabocha/relay-ungap.log
```

Good: a line `ungapped relay db (...)` and then `no backfill after ungap, ok`. If it says `still backfilling` or `disk ..%, stopped`, stop and tell us (step 9). If you ever delete `/opt/kabocha/relay` and resync, start the guard again first: `systemctl start kabocha-ungap-watch`.

## 4. Check it is synced

```bash
journalctl -u kabocha -n 50 --no-pager
```

Synced looks like two `Idle` lines with peers and rising block numbers, one for each chain:

```
[Relaychain] 💤 Idle (25 peers), best: #36,1xx,xxx ...
[Parachain] 💤 Idle (2 peers), best: #8,33x,xxx ...
```

Compare the Kabocha head with the public endpoint:

```bash
curl -s -H 'Content-Type: application/json' -d '{"id":1,"jsonrpc":"2.0","method":"chain_getHeader","params":[]}' http://127.0.0.1:9933 | grep -o '"number":"[^"]*"'
```

and https://kabocha.birdbrain.wtf. The genesis hash must be `0xfeb426ca713f0f46c96465b8f039890370cf6bfd687c9076ea2843f58a6ae8a7`:

```bash
curl -s -H 'Content-Type: application/json' -d '{"id":1,"jsonrpc":"2.0","method":"chain_getBlockHash","params":[0]}' http://127.0.0.1:9933
```

The node will not make blocks yet. That is expected until step 7.

## 5. Make the session key (on the server)

The session key is what signs blocks. It is made inside the node and never leaves it. Kabocha's session key is a single Aura key.

```bash
curl -s -H 'Content-Type: application/json' -d '{"id":1,"jsonrpc":"2.0","method":"author_rotateKeys","params":[]}' http://127.0.0.1:9933
```

The `result` is a 32-byte public key, `0x` followed by 64 hex characters. Keep it for step 6. The private half is in `/opt/kabocha/data/chains/kabocha/keystore/`.

RPC listens on 127.0.0.1 only, so this call works locally and nobody else can make it. Never add `--rpc-external`, `--ws-external` or `--unsafe-*` flags.

Back up the keystore folder somewhere encrypted and off the server. Losing it means rotating keys again. Leaking it means someone else can sign as this collator.

## 6. Tie the key to the operator's account (operator does this, not the server)

The operator needs a Kabocha account. Make it in a wallet on the operator's own device (Talisman, SubWallet or the Polkadot.js extension). **The account's secret phrase never goes on the server and never goes to an agent.** Kabocha addresses use SS58 prefix 27, so they start with `3`.

The account needs a little KAB for fees. Send us the address and we'll send some.

Then sign one transaction:

1. Open https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkabocha-rpc.birdbrain.wtf#/extrinsics
2. Choose the operator's account, then `session` → `setKeys(keys, proof)`
3. `keys`: the key from step 5. `proof`: `0x`
4. Submit and sign

Check: Developer → Chain state → `session.nextKeys(account)` returns the same key.

## 7. Join the collator set

Kabocha's collators are set by its holders. `collatorSelection.desiredCandidates` is 0, so open candidate registration is off and `registerAsCandidate` will fail. Send us the operator's account address and we will put it to the holders in a referendum to add it to `collatorSelection.invulnerables`. Once that passes and a new session starts, the node begins signing its share of blocks without any change on the server. The log shows `🙌 Starting consensus session` and `🎁 Prepared block for proposing`.

## 8. Running it

- Logs: `journalctl -u kabocha -f`
- Restart: `systemctl restart kabocha`
- Disk: check `/` stays under 70%. Today the whole thing is about 20 GB.
- Updates: the chain is due a runtime upgrade (spec 28 → 100), expected in early December if holders approve it. The node program will need replacing around then. We'll publish the new version in this folder with steps, and tell operators first. Do not upgrade the binary from anywhere else.

## Never

- Run the same session key on two machines at once. Two nodes signing with one key fork the chain. To move servers, stop the old node for good first, or rotate to a fresh key (step 5 and 6 again).
- Expose RPC to the internet, or turn on unsafe RPC methods.
- Put the account's secret phrase on the server.
- Skip the guard on a fresh Kusama sync.

## 9. Contact

Birdbrain runs the first collator. Ask in the Kabocha Matrix room, `#kabocha.watercooler:matrix.org`, or through whoever sent you this. Bootnode if peers are slow to appear: `/dns/kabocha-rpc.birdbrain.wtf/tcp/30340/p2p/12D3KooWCuaWFfjNZWVERQPNpsGX4fD4nMnXtDv8RidXvZjo6GbP`.
