-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make a txsim binary build from Makefile and dockerfile #2052
Changes from all commits
8618ba0
327f5d5
f1d9c1c
20c2332
b1e0a68
6f5204b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,11 @@ jobs: | |
uses: celestiaorg/.github/.github/workflows/[email protected] # yamllint disable-line rule:line-length | ||
with: | ||
dockerfile: Dockerfile | ||
|
||
docker-txsim-build: | ||
permissions: | ||
contents: write | ||
packages: write | ||
uses: celestiaorg/.github/.github/workflows/[email protected] | ||
with: | ||
dockerfile: docker/Dockerfile_txsim | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,26 @@ test-coverage: | |||||
@export VERSION=$(VERSION); bash -x scripts/test_cover.sh | ||||||
.PHONY: test-coverage | ||||||
|
||||||
## txsim-install: Install the tx simulator. | ||||||
txsim-install: | ||||||
rootulp marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
@echo "--> Installing tx simulator" | ||||||
@go install -mod=readonly $(BUILD_FLAGS) ./test/cmd/txsim | ||||||
.PHONY: txsim-install | ||||||
|
||||||
## txsim-build: Build the tx simulator binary into the ./build directory. | ||||||
txsim-build: | ||||||
@echo "--> Building tx simulator" | ||||||
@cd ./test/cmd/txsim | ||||||
@mkdir -p build/ | ||||||
@go build $(BUILD_FLAGS) -o build/ ./test/cmd/txsim | ||||||
@go mod tidy -compat=1.20 | ||||||
.PHONY: txsim-build | ||||||
|
||||||
Bidon15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
## docker-txsim-build: Build the Docker image tx simulator. | ||||||
txsim-build-docker: | ||||||
docker build -t ghcr.io/celestiaorg/txsim -f docker/Dockerfile_txsim . | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional]
Suggested change
|
||||||
.PHONY: txsim-build-docker | ||||||
|
||||||
## adr-gen: Download the ADR template from the celestiaorg/.github repo. Ex. `make adr-gen` | ||||||
adr-gen: | ||||||
@echo "--> Downloading ADR template" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Stage 1: generate celestia-appd binary | ||
FROM docker.io/golang:1.20.6-alpine3.17 as builder | ||
# hadolint ignore=DL3018 | ||
RUN apk update && apk add --no-cache \ | ||
gcc \ | ||
git \ | ||
make \ | ||
musl-dev | ||
COPY . /celestia-app | ||
WORKDIR /celestia-app | ||
# we need the celestia-appd build as we might want to create an account | ||
# internally for txsimulation | ||
RUN make build && make txsim-build | ||
|
||
# Stage 2: create a minimal image with the binary | ||
FROM docker.io/alpine:3.18.2 | ||
|
||
# Use UID 10,001 because UIDs below 10,000 are a security risk. | ||
# Ref: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000 | ||
ARG UID=10001 | ||
ARG USER_NAME=celestia | ||
|
||
ENV CELESTIA_HOME=/home/${USER_NAME} | ||
|
||
# hadolint ignore=DL3018 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [no change needed] because this appears copied from another Dockerfile in this repo: https://github.com/rootulp/celestia-app/blob/20c233258d66453028bc77763d424d43277156ba/Dockerfile#L22 but if we're explicitly ignoring a linter rule it's helpful to explain why via a code comment. |
||
RUN apk update && apk add --no-cache \ | ||
bash \ | ||
curl \ | ||
jq \ | ||
# Creates a user with $UID and $GID=$UID | ||
&& adduser ${USER_NAME} \ | ||
-D \ | ||
-g ${USER_NAME} \ | ||
-h ${CELESTIA_HOME} \ | ||
-s /sbin/nologin \ | ||
-u ${UID} | ||
|
||
# Copy in the celestia-appd binary | ||
COPY --from=builder /celestia-app/build/celestia-appd /bin/celestia-appd | ||
COPY --from=builder /celestia-app/build/txsim /bin/txsim | ||
|
||
COPY --chown=${USER_NAME}:${USER_NAME} docker/txsim.sh /opt/entrypoint.sh | ||
|
||
USER ${USER_NAME} | ||
|
||
# grpc, rpc, api ports | ||
EXPOSE 26657 1317 9090 | ||
|
||
ENTRYPOINT [ "/bin/bash", "/opt/entrypoint.sh" ] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,122 @@ | ||||||
# Celestia `txsim` Docker Image Usage Guide | ||||||
|
||||||
The `txsim` binary is a tool that can be used to simulate transactions on the Celestia network. It can be used to test the performance of the Celestia network. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [no change needed][follow up issue] there are other Dockerfiles in this directory. They weren't touched in this PR but maintainers should consider adding to this README what the other files do (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Ideally, we need to make a dedicated issue to document other 2 DockerFiles we have in the repo. |
||||||
This guide provides instructions on how to use the Celestia `txsim` Docker image. The `txsim` Docker image is designed to run the `txsim` binary with a variety of configurable options. | ||||||
|
||||||
## Table of Contents | ||||||
|
||||||
1. [Prerequisites](#prerequisites) | ||||||
2. [Running the Docker Image](#running-the-docker-image) | ||||||
- [Docker Run](#docker-run) | ||||||
- [Docker Compose](#docker-compose) | ||||||
- [Kubernetes Deployment](#kubernetes-deployment) | ||||||
3. [Flag Breakdown](#flag-breakdown) | ||||||
|
||||||
## Prerequisites | ||||||
|
||||||
Before you can use the `txsim` Docker image, you must have a prefunded account set up. The `txsim` binary requires a prefunded account to function correctly. The keyring for this account should be stored in a file that can be accessed by the Docker container. | ||||||
|
||||||
## Running the Docker Image | ||||||
|
||||||
### Docker Run | ||||||
|
||||||
You can run the `txsim` Docker image using the `docker run` command. Here's an example: | ||||||
|
||||||
```bash | ||||||
docker run -it -v ${HOME}/.celestia-app:/home/celestia ghcr.io/celestiaorg/txsim -k 0 -r http://consensus-validator-robusta-rc6.celestia-robusta.com:26657,http://consensus-full-robusta-rc6.celestia-robusta.com:26657 -g consensus-validator-robusta-rc6.celestia-robusta.com:9090 -t 10s -b 10 -d 100 -e 10 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional] I'm a Docker noob so I don't know what these shorthand flags do. The long format flags would help a lot for readability Motivation: https://changelog.com/posts/use-long-flags-when-scripting For example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I get rid of getopts, then yes, we will have long-format flags. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [still not blocking][optional] I don't see why getopts is related to this proposal. The
and I guess
but I think maybe the remaining flags are unique to the script running inside the docker container so they can't be replaced with longer format flags.
Suggested change
|
||||||
``` | ||||||
|
||||||
In this command, the `-v` option is used to mount the `${HOME}/.celestia-app` directory from the host to the `/home/celestia` directory in the Docker container. This allows the `txsim` binary to access the keyring for the prefunded account. | ||||||
|
||||||
### Docker Compose | ||||||
|
||||||
You can also run the `txsim` Docker image using Docker Compose. Here's an example `docker-compose.yml` file: | ||||||
|
||||||
```yaml | ||||||
version: '3' | ||||||
services: | ||||||
txsim: | ||||||
image: ghcr.io/celestiaorg/txsim | ||||||
command: > | ||||||
-k 0 | ||||||
-r http://consensus-validator-robusta-rc6.celestia-robusta.com:26657,http://consensus-full-robusta-rc6.celestia-robusta.com:26657 | ||||||
-g consensus-validator-robusta-rc6.celestia-robusta.com:9090 | ||||||
-t 10s | ||||||
-b 10 | ||||||
-d 100 | ||||||
-e 10 | ||||||
volumes: | ||||||
- /Users/txsimp/.celestia-app:/home/celestia | ||||||
``` | ||||||
|
||||||
In this file, the `volumes` key is used to mount the `/Users/txsimp/.celestia-app` directory from the host to the `/home/celestia` directory in the Docker container. | ||||||
|
||||||
### Kubernetes Deployment | ||||||
|
||||||
Finally, you can run the `txsim` Docker image in a Kubernetes cluster. Here's an example `deployment.yaml` file: | ||||||
|
||||||
```yaml | ||||||
apiVersion: apps/v1 | ||||||
kind: Deployment | ||||||
metadata: | ||||||
name: txsim-deployment | ||||||
spec: | ||||||
replicas: 1 | ||||||
selector: | ||||||
matchLabels: | ||||||
app: txsim | ||||||
template: | ||||||
metadata: | ||||||
labels: | ||||||
app: txsim | ||||||
spec: | ||||||
containers: | ||||||
- name: txsim | ||||||
image: ghcr.io/celestiaorg/txsim | ||||||
args: | ||||||
- "-k" | ||||||
- "0" | ||||||
- "-r" | ||||||
- "http://consensus-validator-robusta-rc6.celestia-robusta.com:26657,http://consensus-full-robusta-rc6.celestia-robusta.com:26657" | ||||||
- "-g" | ||||||
- "consensus-validator-robusta-rc6.celestia-robusta.com:9090" | ||||||
- "-t" | ||||||
- "10s" | ||||||
- "-b" | ||||||
- "10" | ||||||
- "-d" | ||||||
- "100" | ||||||
- "-e" | ||||||
- "10" | ||||||
volumeMounts: | ||||||
- name: keyring-volume | ||||||
mountPath: /home/celestia | ||||||
volumes: | ||||||
- name: keyring-volume | ||||||
hostPath: | ||||||
path: /Users/txsimp/.celestia-app | ||||||
``` | ||||||
|
||||||
In this file, the `volumeMounts` and `volumes` keys are used to mount the `/Users/txsimp/.celestia-app` directory from the host to the `/home/celestia` directory in the Docker container. | ||||||
|
||||||
## Flag Breakdown | ||||||
|
||||||
Here's a breakdown of what each flag means: | ||||||
|
||||||
- `-k`: Whether a new key should be created (1 for yes, 0 for no) | ||||||
- `-p`: The path to the keyring for the prefunded account | ||||||
- `-r`: The RPC endpoints for the `txsim` binary | ||||||
- `-g`: The gRPC endpoints for the `txsim` binary | ||||||
- `-t`: The poll time for the `txsim` binary | ||||||
- `-b`: The number of blob sequences to run | ||||||
- `-a`: The range of blobs to send per PFB in a sequence | ||||||
- `-s`: The range of blob sizes to send | ||||||
- `-m`: The mnemonic for the keyring | ||||||
- `-d`: The seed for the random number generator | ||||||
- `-e`: The number of send sequences to run | ||||||
- `-i`: The amount to send from one account to another | ||||||
- `-v`: The number of send iterations to run per sequence | ||||||
- `-u`: The number of stake sequences to run | ||||||
- `-w`: The amount of initial stake per sequence | ||||||
Comment on lines
+102
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh this legend really helps. It may be even clearer to use longer format flags. I.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, getopts doesn't support long-option flagging and writing a custom for-loop with edge cases of optional arguments is not what I really want to do. As a v2, I'd like to remove completely this script and make it as server with REST APIs that we can trigger via a dashboard. |
||||||
|
||||||
Please replace the placeholders in the examples with the actual values you want to use. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
|
||
CREATE_KEY=0 | ||
KEY_PATH="/home/celestia" | ||
RPC_ENDPOINTS="" | ||
GRPC_ENDPOINTS="" | ||
POLL_TIME="" | ||
BLOB=0 | ||
BLOB_AMOUNTS="1" | ||
BLOB_SIZES="100-1000" | ||
KEY_MNEMONIC="" | ||
SEED=0 | ||
SEND=0 | ||
SEND_AMOUNT=1000 | ||
SEND_ITERATIONS=1000 | ||
STAKE=0 | ||
STAKE_VALUE=1000 | ||
|
||
while getopts "k:p:r:g:t:b:a:s:m:d:e:i:v:u:w:" opt; do | ||
case ${opt} in | ||
k ) | ||
CREATE_KEY=$OPTARG | ||
;; | ||
p ) | ||
KEY_PATH=$OPTARG | ||
;; | ||
r ) | ||
RPC_ENDPOINTS=$OPTARG | ||
;; | ||
g ) | ||
GRPC_ENDPOINTS=$OPTARG | ||
;; | ||
t ) | ||
POLL_TIME=$OPTARG | ||
;; | ||
b ) | ||
BLOB=$OPTARG | ||
;; | ||
a ) | ||
BLOB_AMOUNTS=$OPTARG | ||
;; | ||
s ) | ||
BLOB_SIZES=$OPTARG | ||
;; | ||
m ) | ||
KEY_MNEMONIC=$OPTARG | ||
;; | ||
d ) | ||
SEED=$OPTARG | ||
;; | ||
e ) | ||
SEND=$OPTARG | ||
;; | ||
i ) | ||
SEND_AMOUNT=$OPTARG | ||
;; | ||
v ) | ||
SEND_ITERATIONS=$OPTARG | ||
;; | ||
u ) | ||
STAKE=$OPTARG | ||
;; | ||
w ) | ||
STAKE_VALUE=$OPTARG | ||
;; | ||
\? ) | ||
echo "Invalid option: $OPTARG" 1>&2 | ||
exit 1 | ||
;; | ||
: ) | ||
echo "Invalid option: $OPTARG requires an argument" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
if [ "$CREATE_KEY" -eq 1 ]; then | ||
echo "Creating a new keyring-test for the txsim" | ||
/bin/celestia-appd keys add sim --keyring-backend test --home $KEY_PATH | ||
sleep 5 | ||
fi | ||
|
||
# Running a tx simulator | ||
txsim --key-path $KEY_PATH \ | ||
--rpc-endpoints $RPC_ENDPOINTS \ | ||
--grpc-endpoints $GRPC_ENDPOINTS \ | ||
--poll-time $POLL_TIME \ | ||
--blob $BLOB \ | ||
--blob-amounts $BLOB_AMOUNTS \ | ||
--blob-sizes $BLOB_SIZES \ | ||
--key-mnemonic "$KEY_MNEMONIC" \ | ||
--seed $SEED \ | ||
--send $SEND \ | ||
--send-amount $SEND_AMOUNT \ | ||
--send-iterations $SEND_ITERATIONS \ | ||
--stake $STAKE \ | ||
--stake-value $STAKE_VALUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we would just combine and put as a matrix?
REF: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#defining-the-maximum-number-of-concurrent-jobs
Github will try and run them in parallel, so unless there is a bug this is trying to work around, making them separate doesn't speed things up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also can be a follow up, doesn't need to block in PR. 👍