Skip to content

Commit

Permalink
rework proto cruncher to use new rust tz-proto-vanity (#575)
Browse files Browse the repository at this point in the history
The previous proto cruncher was in python and embedded in this helm
chart, running in the utils container. Our new one leverages Igor's
project:

https://github.com/oxheadalpha/tz-proto-vanity
  • Loading branch information
nicolasochem authored Apr 11, 2023
1 parent 79bc192 commit cf7bea5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 100 deletions.
8 changes: 8 additions & 0 deletions charts/tezos-proto-cruncher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
This chart deploys a daemonset to perform a brute-force search
of a vanity protocol name.

It leverages this project:

https://github.com/oxheadalpha/tz-proto-vanity

It runs in a daemonset and uploads matches to a bucket.

Thus you can run arbitrarily large k8s clusters for this purpose and the daemon will utilize all nodes to their full potential.

See values.yaml for details.
79 changes: 0 additions & 79 deletions charts/tezos-proto-cruncher/scripts/proto-cruncher.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import boto3
import os
import subprocess
import sys

BUCKET_NAME = os.environ["BUCKET_NAME"]
BUCKET_ENDPOINT_URL = os.environ["BUCKET_ENDPOINT_URL"]
BUCKET_REGION = os.environ["BUCKET_REGION"]

PROTO_NAME = os.environ["PROTO_NAME"]

import boto3
VANITY_STRING = os.environ["VANITY_STRING"]

s3 = boto3.resource(
"s3", region_name=BUCKET_REGION, endpoint_url=f"https://{BUCKET_ENDPOINT_URL}"
)

print(f"Downloading {PROTO_NAME}")
proto_file = f"/{PROTO_NAME}"
proto_file = f"/opt/{PROTO_NAME}"
s3_bucket = s3.Bucket(BUCKET_NAME)
try:
s3_bucket.download_file(PROTO_NAME, proto_file)
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] == "404":
print("The object does not exist.")
sys.exit(1)
else:
raise
cmd = subprocess.Popen(['/opt/tz-proto-vanity', f'/opt/{PROTO_NAME}', VANITY_STRING, '-f', 'csv'], stdout=subprocess.PIPE)
next(cmd.stdout) # ignore first line of csv
for line in cmd.stdout:
linesplit = line.decode("utf-8").split(",")
print(f"found vanity hash {linesplit[0]} with nonce {linesplit[1]}")
s3.Object(BUCKET_NAME, f"{PROTO_NAME}_{linesplit[0]}").put(Body=linesplit[1])
11 changes: 3 additions & 8 deletions charts/tezos-proto-cruncher/scripts/tezos-proto-cruncher.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
set -eo pipefail
apk add parallel
apk add py3-pip
pip install boto3

python /proto-downloader.py

if [ -z "${NUM_PARALLEL_PROCESSES}" ]; then
# Launch one process per CPU core to maximize utilization
NUM_PARALLEL_PROCESSES=$(grep -c ^processor /proc/cpuinfo)
fi
seq $NUM_PARALLEL_PROCESSES | parallel --ungroup python /proto-cruncher.py /${PROTO_NAME}
export PYTHONUNBUFFERED=1
python /tezos-proto-cruncher.py
6 changes: 2 additions & 4 deletions charts/tezos-proto-cruncher/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@ apiVersion: v1
metadata:
name: scripts
data:
proto-cruncher.py: |
{{ tpl ($.Files.Get (print "scripts/proto-cruncher.py")) $ | indent 4 }}
proto-downloader.py: |
{{ tpl ($.Files.Get (print "scripts/proto-downloader.py")) $ | indent 4 }}
tezos-proto-cruncher.py: |
{{ tpl ($.Files.Get (print "scripts/tezos-proto-cruncher.py")) $ | indent 4 }}
9 changes: 3 additions & 6 deletions charts/tezos-proto-cruncher/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ spec:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.tezos_k8s_images.utils }}"
image: "{{ .Values.images.tz_proto_vanity }}"
volumeMounts:
- mountPath: /proto-cruncher.py
- mountPath: /tezos-proto-cruncher.py
name: scripts
subPath: proto-cruncher.py
- mountPath: /proto-downloader.py
name: scripts
subPath: proto-downloader.py
subPath: tezos-proto-cruncher.py
envFrom:
- secretRef:
name: s3-secrets
Expand Down
2 changes: 2 additions & 0 deletions charts/tezos-proto-cruncher/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
images:
tz_proto_vanity: ghcr.io/oxheadalpha/tz-proto-vanity:latest
# tezos-proto-cruncher downloads a protocol in binary format
# from a S3 bucket, and writes the results in the same bucket.
# Put the credentials for access to your bucket below.
Expand Down

0 comments on commit cf7bea5

Please sign in to comment.