Skip to content

Commit caf2781

Browse files
authored
Merge pull request #691 from galacticcouncil/fork
feat: fork testnet
2 parents dbecb00 + a3884f1 commit caf2781

8 files changed

Lines changed: 2826 additions & 0 deletions

File tree

launch-configs/fork/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
state.json
2+
forked-chainspec.json
3+
data/

launch-configs/fork/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM node:18-bookworm
2+
3+
RUN apt-get update && apt-get install -y \
4+
curl \
5+
wget \
6+
nodejs \
7+
npm \
8+
ca-certificates \
9+
&& update-ca-certificates \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /zombienet/Basilisk-node/launch-configs/fork
13+
14+
RUN wget -q https://github.com/paritytech/zombienet/releases/download/v1.3.128/zombienet-linux-x64 -O /usr/local/bin/zombienet && \
15+
chmod +x /usr/local/bin/zombienet
16+
RUN zombienet version
17+
18+
ARG POLKADOT_SDK_VERSION=latest
19+
20+
RUN mkdir -p /zombienet/polkadot-sdk/target/release
21+
RUN if [ "$POLKADOT_SDK_VERSION" = "latest" ]; then \
22+
DOWNLOAD_URL="https://github.com/paritytech/polkadot-sdk/releases/latest/download"; \
23+
else \
24+
DOWNLOAD_URL="https://github.com/paritytech/polkadot-sdk/releases/download/$POLKADOT_SDK_VERSION"; \
25+
fi && \
26+
for binary in polkadot polkadot-execute-worker polkadot-prepare-worker; do \
27+
wget -q $DOWNLOAD_URL/$binary \
28+
-O /zombienet/polkadot-sdk/target/release/$binary \
29+
&& chmod +x /zombienet/polkadot-sdk/target/release/$binary \
30+
&& /zombienet/polkadot-sdk/target/release/$binary --version; \
31+
done
32+
33+
ARG BASILISK_BIN_URL=https://github.com/galacticcouncil/Basilisk-node/releases/latest/download
34+
ARG SCRAPER_URL=https://github.com/galacticcouncil/hydration-node/releases/latest/download
35+
36+
RUN mkdir -p /zombienet/Basilisk-node/target/release
37+
RUN wget -q $BASILISK_BIN_URL/basilisk -O /zombienet/Basilisk-node/target/release/basilisk && \
38+
wget -q $SCRAPER_URL/scraper -O /zombienet/Basilisk-node/target/release/scraper && \
39+
chmod +x /zombienet/Basilisk-node/target/release/*
40+
RUN /zombienet/Basilisk-node/target/release/basilisk --version
41+
42+
COPY . .
43+
44+
RUN npm i
45+
46+
VOLUME /zombienet/Basilisk-node/launch-configs/fork/data
47+
EXPOSE 9988
48+
49+
CMD npm start

launch-configs/fork/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
starts zombienet instance with forked basilisk state downloaded from either:
2+
- rpc endpoint in `STATE_RPC` (defaults to `wss://rpc.basilisk.cloud`) and block `STATE_BLOCK` (latest finalized by default)
3+
- url of json defined in `STATE_SOURCE`
4+
5+
para_id: 2090, relay: rococo-local (kusama-local was retired from the polkadot binary; the local relay is cosmetic for a fork test)
6+
7+
### run with docker
8+
9+
```
10+
docker run -d -p 9988:9988 galacticcouncil/fork:basilisk
11+
```
12+
13+
### run locally
14+
15+
- node >18 required
16+
- you have to have all binaries present on correct paths in `config.json`
17+
18+
```
19+
npm i && npm start
20+
```
21+
22+
### run with live PROD chainspec
23+
24+
- It scrapes the chainspec from the latest finalized block of basilisk mainnet, then spins up the fork via zombienet
25+
26+
```
27+
npm run start:live
28+
```
29+
30+
### run with custom chainspec
31+
32+
If you want to run fork with a custom chainspec, do the following:
33+
34+
1. Save a chainspec via the scraper (basilisk reuses hydration-node's `scraper` binary).
35+
2. Place it at `./data/state.json`.
36+
3. Run `npm run start:raw`.
37+
38+
### preauthorize a runtime upgrade
39+
40+
Set `AUTHORIZE_UPGRADE_CODE_HASH=0x<32-byte wasm hash>` in the container env. The fork
41+
comes up with `System.AuthorizedUpgrade` populated, so a single
42+
`system.applyAuthorizedUpgrade(code)` call enacts the new wasm — no governance step.
43+
44+
Pass `AUTHORIZE_UPGRADE_CHECK_VERSION=false` to skip the spec-version check (default: true).

launch-configs/fork/config.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"settings": {
3+
"timeout": 1000,
4+
"provider": "native"
5+
},
6+
"relaychain": {
7+
"default_command": "../../../polkadot-sdk/target/release/polkadot",
8+
"chain": "rococo-local",
9+
"default_args": [
10+
"--no-hardware-benchmarks",
11+
"--database=paritydb"
12+
],
13+
"genesis": {
14+
"runtimeGenesis": {
15+
"patch": {
16+
"configuration": {
17+
"config": {
18+
"async_backing_params": {
19+
"max_candidate_depth": 3,
20+
"allowed_ancestry_len": 2
21+
}
22+
}
23+
}
24+
}
25+
}
26+
},
27+
"nodes": [
28+
{
29+
"name": "alice",
30+
"rpc_port": 9944,
31+
"validator": true
32+
},
33+
{
34+
"name": "bob",
35+
"rpc_port": 9955,
36+
"validator": true
37+
},
38+
{
39+
"name": "charlie",
40+
"rpc_port": 9966,
41+
"validator": true
42+
},
43+
{
44+
"name": "dave",
45+
"rpc_port": 9977,
46+
"validator": true
47+
}
48+
]
49+
},
50+
"types": {},
51+
"hrmp_channels": [],
52+
"parachains": [
53+
{
54+
"id": 2090,
55+
"cumulus_based": true,
56+
"chain": "local",
57+
"chain_spec_path": "data/forked-chainspec.json",
58+
"collators": [
59+
{
60+
"name": "alice",
61+
"command": "../../target/release/basilisk",
62+
"rpc_port": 9999,
63+
"args": [
64+
"--no-hardware-benchmarks",
65+
"--force-authoring",
66+
"--database=paritydb",
67+
"--pool-type=fork-aware",
68+
"--pruning=archive",
69+
"--rpc-max-connections=5000",
70+
"--tx-ban-seconds=5",
71+
"--log=info"
72+
]
73+
},
74+
{
75+
"name": "bob",
76+
"command": "../../target/release/basilisk",
77+
"rpc_port": 9989,
78+
"args": [
79+
"--no-hardware-benchmarks",
80+
"--force-authoring",
81+
"--database=paritydb",
82+
"--pool-type=fork-aware",
83+
"--pruning=archive",
84+
"--log=info"
85+
]
86+
}
87+
]
88+
}
89+
]
90+
}

launch-configs/fork/get-state.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Define state file path
4+
STATE_FILE="./data/state.json"
5+
6+
# Check if state file already exists
7+
if [ -f "$STATE_FILE" ]; then
8+
echo "State file already exists at $STATE_FILE. Skipping download/scrape."
9+
exit 0
10+
fi
11+
12+
# Ensure data directory exists
13+
mkdir -p ./data
14+
15+
# Determine which command to run based on environment variables
16+
if [ -n "$STATE_RPC" ]; then
17+
echo "Using RPC endpoint: $STATE_RPC"
18+
19+
if [ -n "$STATE_BLOCK" ]; then
20+
echo "Using block: $STATE_BLOCK"
21+
fi
22+
23+
COMMAND="npm run state:scrape"
24+
elif [ -n "$STATE_SOURCE" ]; then
25+
echo "Using custom source: $STATE_SOURCE"
26+
COMMAND="npm run state:download"
27+
else
28+
echo "Using default RPC endpoint"
29+
COMMAND="npm run state:scrape"
30+
fi
31+
32+
echo "Executing: $COMMAND"
33+
34+
if eval $COMMAND; then
35+
if [ -f "$STATE_FILE" ]; then
36+
echo "Successfully created state file at $STATE_FILE"
37+
else
38+
echo "Command completed but state file was not created!"
39+
exit 1
40+
fi
41+
else
42+
echo "Command execution failed"
43+
exit 1
44+
fi

0 commit comments

Comments
 (0)