Skip to content

Commit

Permalink
Add initial basic simulator support (#233)
Browse files Browse the repository at this point in the history
* Add initial basic simulator support

* Add support for persistent mnemonic for simulator, and make the key available when using sim

* ADd basic readme for now
  • Loading branch information
cmmarslender authored Feb 21, 2024
1 parent 90de635 commit 392160e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/*
sim-root
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ENV farmer="false"
# netcat: Healthchecking the daemon
# yq: changing config settings
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y sudo tzdata curl netcat-traditional && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y sudo tzdata curl netcat-traditional jq && \
rm -rf /var/lib/apt/lists/* && \
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata
Expand Down
22 changes: 22 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ cd /chia-blockchain || exit 1
# shellcheck disable=SC1091
. ./activate

# Set a few overrides if the service variable contains simulator
if [ -z "${service##*simulator*}" ]; then
echo "Setting up environment for simulator..."
export CHIA_ROOT=/root/.chia/simulator/main
export self_hostname="0.0.0.0"

if [ -f /root/.chia/simulator/mnemonic ]; then
echo "Using provided mnemonic from /root/.chia/simulator/mnemonic"
# Use awk to trim leading and trailing whitespace while preserving internal spaces
mnemonic=$(awk '{$1=$1};1' /root/.chia/simulator/mnemonic)
fi

if [ -n "$mnemonic" ]; then # Check if mnemonic is non-empty after trimming
chia dev sim create --docker-mode --mnemonic "${mnemonic}"
else
chia dev sim create --docker-mode
fi

chia stop -d all
chia keys show --show-mnemonic-seed --json | jq -r '.keys[0].mnemonic' > /root/.chia/simulator/mnemonic
fi

# shellcheck disable=SC2086
chia ${chia_args} init --fix-ssl-permissions

Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,9 @@ readinessProbe:
```

See [Configure Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes) for more information about configuring readiness and liveness probes for Kubernetes clusters. The `initialDelaySeconds` parameter may need to be adjusted higher or lower depending on the speed to start up on the host the container is running on.

## Simulator

`docker run -e service=simulator -v /local/path/to/simulator:/root/.chia/simulator ghcr.io/chia-network/chia:latest`

Mounts the simulator root to the provided local path to make the test plots and the mnemonic persistent. Mnemonic will be available at /local/path/to/simulator/mnemonic

0 comments on commit 392160e

Please sign in to comment.